mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-25 00:50:31 +00:00
Small fixes [release]
This commit is contained in:
parent
1f9d5ab2e6
commit
b881e548fc
8 changed files with 26 additions and 33 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -28,8 +28,6 @@ public interface OsType {
|
|||
|
||||
String getTempDirectory(ShellControl pc) throws Exception;
|
||||
|
||||
String normalizeFileName(String file);
|
||||
|
||||
Map<String, String> 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<String, String> 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";
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<FileEntry> 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();
|
||||
}
|
||||
|
|
|
@ -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<FileEntry> listFiles(String file) throws Exception;
|
||||
|
||||
|
|
2
version
2
version
|
@ -1 +1 @@
|
|||
0.5.16
|
||||
0.5.17
|
Loading…
Reference in a new issue