diff --git a/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java b/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java index ea2bc111..b02e495a 100644 --- a/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java +++ b/app/src/main/java/io/xpipe/app/browser/FileSystemHelper.java @@ -60,6 +60,11 @@ public class FileSystemHelper { .getShellDialect() .normalizeDirectory(shell.get(), path) .readOrThrow(); + + if (!model.getFileSystem().directoryExists(normalized)) { + throw new IllegalArgumentException(String.format("Directory %s does not exist", normalized)); + } + return FileNames.toDirectory(normalized); } diff --git a/core/src/main/java/io/xpipe/core/process/CommandControl.java b/core/src/main/java/io/xpipe/core/process/CommandControl.java index 7ee42807..de84debc 100644 --- a/core/src/main/java/io/xpipe/core/process/CommandControl.java +++ b/core/src/main/java/io/xpipe/core/process/CommandControl.java @@ -39,6 +39,12 @@ public interface CommandControl extends ProcessControl { } } + default boolean executeAndCheck() throws Exception { + try (var c = start()) { + return c.discardAndCheckExit(); + } + } + ShellControl getParent(); InputStream startExternalStdout() throws Exception; diff --git a/core/src/main/java/io/xpipe/core/process/OsType.java b/core/src/main/java/io/xpipe/core/process/OsType.java index 45b1c934..aa7ff088 100644 --- a/core/src/main/java/io/xpipe/core/process/OsType.java +++ b/core/src/main/java/io/xpipe/core/process/OsType.java @@ -28,8 +28,6 @@ public interface OsType { String getTempDirectory(ShellControl pc) throws Exception; - String normalizeFileName(String file); - Map getProperties(ShellControl pc) throws Exception; String determineOperatingSystemName(ShellControl pc) throws Exception; @@ -51,11 +49,6 @@ public interface OsType { return pc.executeStringSimpleCommand(pc.getShellDialect().getPrintEnvironmentVariableCommand("TEMP")); } - @Override - public String normalizeFileName(String file) { - return String.join("\\", file.split("[\\\\/]+")); - } - @Override public Map getProperties(ShellControl pc) throws Exception { try (CommandControl c = pc.command("systeminfo").start()) { @@ -84,11 +77,6 @@ public interface OsType { return "/tmp/"; } - @Override - public String normalizeFileName(String file) { - return String.join("/", file.split("[\\\\/]+")); - } - @Override public String getName() { return "Linux"; @@ -154,11 +142,6 @@ public interface OsType { return found; } - @Override - public String normalizeFileName(String file) { - return String.join("/", file.split("[\\\\/]+")); - } - @Override public String getName() { return "Mac"; diff --git a/core/src/main/java/io/xpipe/core/process/ShellDialect.java b/core/src/main/java/io/xpipe/core/process/ShellDialect.java index 5bca7da1..1bab1db3 100644 --- a/core/src/main/java/io/xpipe/core/process/ShellDialect.java +++ b/core/src/main/java/io/xpipe/core/process/ShellDialect.java @@ -2,7 +2,6 @@ package io.xpipe.core.process; import com.fasterxml.jackson.annotation.JsonTypeInfo; import io.xpipe.core.charsetter.NewLine; -import io.xpipe.core.charsetter.StreamCharset; import io.xpipe.core.store.FileSystem; import java.nio.charset.Charset; @@ -14,9 +13,7 @@ import java.util.stream.Stream; @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") public interface ShellDialect { - default StreamCharset getTextFileCharset(ShellControl sc) { - return StreamCharset.get(sc.getCharset(), false); - } + CommandControl directoryExists(ShellControl shellControl, String directory); CommandControl normalizeDirectory(ShellControl shellControl, String directory); diff --git a/core/src/main/java/io/xpipe/core/process/ShellDialects.java b/core/src/main/java/io/xpipe/core/process/ShellDialects.java index b1208514..8adf19aa 100644 --- a/core/src/main/java/io/xpipe/core/process/ShellDialects.java +++ b/core/src/main/java/io/xpipe/core/process/ShellDialects.java @@ -26,10 +26,10 @@ public class ShellDialects { CMD = byName("cmd"); POWERSHELL = byName("powershell"); - SH = byName("sh"); DASH = byName("dash"); BASH = byName("bash"); ZSH = byName("zsh"); + SH = byName("sh"); } @Override diff --git a/core/src/main/java/io/xpipe/core/store/ConnectionFileSystem.java b/core/src/main/java/io/xpipe/core/store/ConnectionFileSystem.java index 8207e14c..2c7be8d8 100644 --- a/core/src/main/java/io/xpipe/core/store/ConnectionFileSystem.java +++ b/core/src/main/java/io/xpipe/core/store/ConnectionFileSystem.java @@ -31,7 +31,9 @@ public class ConnectionFileSystem implements FileSystem { } @Override - public boolean isDirectory(String file) throws Exception{return true;} + public boolean directoryExists(String file) throws Exception{ + return shellControl.getShellDialect().directoryExists(shellControl, file).executeAndCheck(); + } @Override public Stream listFiles(String file) throws Exception { @@ -57,21 +59,21 @@ public class ConnectionFileSystem implements FileSystem { @Override public InputStream openInput(String file) throws Exception { return shellControl.command(proc -> - proc.getShellDialect().getFileReadCommand(proc.getOsType().normalizeFileName(file))) + proc.getShellDialect().getFileReadCommand(file)) .startExternalStdout(); } @Override public OutputStream openOutput(String file) throws Exception { return shellControl.getShellDialect() - .createStreamFileWriteCommand(shellControl, shellControl.getOsType().normalizeFileName(file)) + .createStreamFileWriteCommand(shellControl, file) .startExternalStdin(); } @Override public boolean exists(String file) throws Exception { try (var pc = shellControl.command(proc -> proc.getShellDialect() - .getFileExistsCommand(proc.getOsType().normalizeFileName(file))).complex() + .getFileExistsCommand(file)).complex() .start()) { return pc.discardAndCheckExit(); } @@ -80,7 +82,7 @@ public class ConnectionFileSystem implements FileSystem { @Override public void delete(String file) throws Exception { try (var pc = shellControl.command(proc -> proc.getShellDialect() - .getFileDeleteCommand(proc.getOsType().normalizeFileName(file))).complex() + .getFileDeleteCommand(file)).complex() .start()) { pc.discardOrThrow(); } @@ -89,7 +91,7 @@ public class ConnectionFileSystem implements FileSystem { @Override public void copy(String file, String newFile) throws Exception { try (var pc = shellControl.command(proc -> proc.getShellDialect() - .getFileCopyCommand(proc.getOsType().normalizeFileName(file), proc.getOsType().normalizeFileName(newFile))).complex() + .getFileCopyCommand(file, newFile)).complex() .start()) { pc.discardOrThrow(); } @@ -98,7 +100,7 @@ public class ConnectionFileSystem implements FileSystem { @Override public void move(String file, String newFile) throws Exception { try (var pc = shellControl.command(proc -> proc.getShellDialect() - .getFileMoveCommand(proc.getOsType().normalizeFileName(file), proc.getOsType().normalizeFileName(newFile))).complex() + .getFileMoveCommand(file, newFile)).complex() .start()) { pc.discardOrThrow(); } @@ -107,7 +109,7 @@ public class ConnectionFileSystem implements FileSystem { @Override public boolean mkdirs(String file) throws Exception { try (var pc = shellControl.command(proc -> proc.getShellDialect() - .getMkdirsCommand(proc.getOsType().normalizeFileName(file))).complex() + .getMkdirsCommand(file)).complex() .start()) { return pc.discardAndCheckExit(); } @@ -116,7 +118,7 @@ public class ConnectionFileSystem implements FileSystem { @Override public void touch(String file) throws Exception { try (var pc = shellControl.command(proc -> proc.getShellDialect() - .getFileTouchCommand(proc.getOsType().normalizeFileName(file))).complex() + .getFileTouchCommand(file)).complex() .start()) { pc.discardOrThrow(); } diff --git a/core/src/main/java/io/xpipe/core/store/FileSystem.java b/core/src/main/java/io/xpipe/core/store/FileSystem.java index fb784589..b3b569a1 100644 --- a/core/src/main/java/io/xpipe/core/store/FileSystem.java +++ b/core/src/main/java/io/xpipe/core/store/FileSystem.java @@ -63,7 +63,7 @@ public interface FileSystem extends Closeable, AutoCloseable { void touch(String file) throws Exception; - boolean isDirectory(String file) throws Exception; + boolean directoryExists(String file) throws Exception; Stream listFiles(String file) throws Exception; diff --git a/version b/version index a6db491d..0d240c6b 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.5.16 \ No newline at end of file +0.5.17 \ No newline at end of file