Improve os detection and file existance checks

This commit is contained in:
crschnick
2023-04-06 15:46:22 +00:00
parent 4726ad975c
commit fe396e1b11
8 changed files with 10 additions and 9 deletions
@@ -82,7 +82,7 @@ public class FileStore extends JacksonizedValue implements FilenameStore, Stream
@Override
public boolean canOpen() throws Exception {
return fileSystem.createFileSystem().open().exists(path);
return fileSystem.createFileSystem().open().fileExists(path);
}
@Override
@@ -123,7 +123,7 @@ public interface ShellDialect {
String getFileDeleteCommand(String file);
String getFileExistsCommand(String file);
CommandControl createFileExistsCommand(ShellControl sc, String file);
String getFileTouchCommand(String file);
@@ -76,9 +76,9 @@ public class ConnectionFileSystem implements FileSystem {
}
@Override
public boolean exists(String file) throws Exception {
try (var pc = shellControl.command(proc -> proc.getShellDialect()
.getFileExistsCommand(file)).complex()
public boolean fileExists(String file) throws Exception {
try (var pc = shellControl.getShellDialect()
.createFileExistsCommand(shellControl, file).complex()
.start()) {
return pc.discardAndCheckExit();
}
@@ -51,7 +51,7 @@ public interface FileSystem extends Closeable, AutoCloseable {
OutputStream openOutput(String file) throws Exception;
public boolean exists(String file) throws Exception;
public boolean fileExists(String file) throws Exception;
public void delete(String file) throws Exception;
@@ -42,6 +42,7 @@ public class XPipeSession {
: UuidHelper.parse(() -> Files.readString(sessionFile)).orElse(UUID.randomUUID());
try {
//TODO: People might move their page file to another drive
if (OsType.getLocal().equals(OsType.WINDOWS)) {
var pf = Path.of("C:\\pagefile.sys");
BasicFileAttributes attr = Files.readAttributes(pf, BasicFileAttributes.class);
@@ -23,7 +23,7 @@ public class XPipeTempDirectory {
var base = proc.getOsType().getTempDirectory(proc);
var dir = FileNames.join(base, "xpipe");
if (!proc.executeBooleanSimpleCommand(proc.getShellDialect().getFileExistsCommand(dir))) {
if (!proc.getShellDialect().createFileExistsCommand(proc, dir).executeAndCheck()) {
proc.executeSimpleCommand(proc.getShellDialect().getMkdirsCommand(dir),
"Unable to access or create temporary directory " + dir);