mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-09-30 00:56:56 +13: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()
|
.getShellDialect()
|
||||||
.normalizeDirectory(shell.get(), path)
|
.normalizeDirectory(shell.get(), path)
|
||||||
.readOrThrow();
|
.readOrThrow();
|
||||||
|
|
||||||
|
if (!model.getFileSystem().directoryExists(normalized)) {
|
||||||
|
throw new IllegalArgumentException(String.format("Directory %s does not exist", normalized));
|
||||||
|
}
|
||||||
|
|
||||||
return FileNames.toDirectory(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();
|
ShellControl getParent();
|
||||||
|
|
||||||
InputStream startExternalStdout() throws Exception;
|
InputStream startExternalStdout() throws Exception;
|
||||||
|
|
|
@ -28,8 +28,6 @@ public interface OsType {
|
||||||
|
|
||||||
String getTempDirectory(ShellControl pc) throws Exception;
|
String getTempDirectory(ShellControl pc) throws Exception;
|
||||||
|
|
||||||
String normalizeFileName(String file);
|
|
||||||
|
|
||||||
Map<String, String> getProperties(ShellControl pc) throws Exception;
|
Map<String, String> getProperties(ShellControl pc) throws Exception;
|
||||||
|
|
||||||
String determineOperatingSystemName(ShellControl pc) throws Exception;
|
String determineOperatingSystemName(ShellControl pc) throws Exception;
|
||||||
|
@ -51,11 +49,6 @@ public interface OsType {
|
||||||
return pc.executeStringSimpleCommand(pc.getShellDialect().getPrintEnvironmentVariableCommand("TEMP"));
|
return pc.executeStringSimpleCommand(pc.getShellDialect().getPrintEnvironmentVariableCommand("TEMP"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String normalizeFileName(String file) {
|
|
||||||
return String.join("\\", file.split("[\\\\/]+"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> getProperties(ShellControl pc) throws Exception {
|
public Map<String, String> getProperties(ShellControl pc) throws Exception {
|
||||||
try (CommandControl c = pc.command("systeminfo").start()) {
|
try (CommandControl c = pc.command("systeminfo").start()) {
|
||||||
|
@ -84,11 +77,6 @@ public interface OsType {
|
||||||
return "/tmp/";
|
return "/tmp/";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String normalizeFileName(String file) {
|
|
||||||
return String.join("/", file.split("[\\\\/]+"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Linux";
|
return "Linux";
|
||||||
|
@ -154,11 +142,6 @@ public interface OsType {
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String normalizeFileName(String file) {
|
|
||||||
return String.join("/", file.split("[\\\\/]+"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Mac";
|
return "Mac";
|
||||||
|
|
|
@ -2,7 +2,6 @@ package io.xpipe.core.process;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
import io.xpipe.core.charsetter.NewLine;
|
import io.xpipe.core.charsetter.NewLine;
|
||||||
import io.xpipe.core.charsetter.StreamCharset;
|
|
||||||
import io.xpipe.core.store.FileSystem;
|
import io.xpipe.core.store.FileSystem;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
@ -14,9 +13,7 @@ import java.util.stream.Stream;
|
||||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
|
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
|
||||||
public interface ShellDialect {
|
public interface ShellDialect {
|
||||||
|
|
||||||
default StreamCharset getTextFileCharset(ShellControl sc) {
|
CommandControl directoryExists(ShellControl shellControl, String directory);
|
||||||
return StreamCharset.get(sc.getCharset(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
CommandControl normalizeDirectory(ShellControl shellControl, String directory);
|
CommandControl normalizeDirectory(ShellControl shellControl, String directory);
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,10 @@ public class ShellDialects {
|
||||||
|
|
||||||
CMD = byName("cmd");
|
CMD = byName("cmd");
|
||||||
POWERSHELL = byName("powershell");
|
POWERSHELL = byName("powershell");
|
||||||
SH = byName("sh");
|
|
||||||
DASH = byName("dash");
|
DASH = byName("dash");
|
||||||
BASH = byName("bash");
|
BASH = byName("bash");
|
||||||
ZSH = byName("zsh");
|
ZSH = byName("zsh");
|
||||||
|
SH = byName("sh");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -31,7 +31,9 @@ public class ConnectionFileSystem implements FileSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
@Override
|
||||||
public Stream<FileEntry> listFiles(String file) throws Exception {
|
public Stream<FileEntry> listFiles(String file) throws Exception {
|
||||||
|
@ -57,21 +59,21 @@ public class ConnectionFileSystem implements FileSystem {
|
||||||
@Override
|
@Override
|
||||||
public InputStream openInput(String file) throws Exception {
|
public InputStream openInput(String file) throws Exception {
|
||||||
return shellControl.command(proc ->
|
return shellControl.command(proc ->
|
||||||
proc.getShellDialect().getFileReadCommand(proc.getOsType().normalizeFileName(file)))
|
proc.getShellDialect().getFileReadCommand(file))
|
||||||
.startExternalStdout();
|
.startExternalStdout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OutputStream openOutput(String file) throws Exception {
|
public OutputStream openOutput(String file) throws Exception {
|
||||||
return shellControl.getShellDialect()
|
return shellControl.getShellDialect()
|
||||||
.createStreamFileWriteCommand(shellControl, shellControl.getOsType().normalizeFileName(file))
|
.createStreamFileWriteCommand(shellControl, file)
|
||||||
.startExternalStdin();
|
.startExternalStdin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean exists(String file) throws Exception {
|
public boolean exists(String file) throws Exception {
|
||||||
try (var pc = shellControl.command(proc -> proc.getShellDialect()
|
try (var pc = shellControl.command(proc -> proc.getShellDialect()
|
||||||
.getFileExistsCommand(proc.getOsType().normalizeFileName(file))).complex()
|
.getFileExistsCommand(file)).complex()
|
||||||
.start()) {
|
.start()) {
|
||||||
return pc.discardAndCheckExit();
|
return pc.discardAndCheckExit();
|
||||||
}
|
}
|
||||||
|
@ -80,7 +82,7 @@ public class ConnectionFileSystem implements FileSystem {
|
||||||
@Override
|
@Override
|
||||||
public void delete(String file) throws Exception {
|
public void delete(String file) throws Exception {
|
||||||
try (var pc = shellControl.command(proc -> proc.getShellDialect()
|
try (var pc = shellControl.command(proc -> proc.getShellDialect()
|
||||||
.getFileDeleteCommand(proc.getOsType().normalizeFileName(file))).complex()
|
.getFileDeleteCommand(file)).complex()
|
||||||
.start()) {
|
.start()) {
|
||||||
pc.discardOrThrow();
|
pc.discardOrThrow();
|
||||||
}
|
}
|
||||||
|
@ -89,7 +91,7 @@ public class ConnectionFileSystem implements FileSystem {
|
||||||
@Override
|
@Override
|
||||||
public void copy(String file, String newFile) throws Exception {
|
public void copy(String file, String newFile) throws Exception {
|
||||||
try (var pc = shellControl.command(proc -> proc.getShellDialect()
|
try (var pc = shellControl.command(proc -> proc.getShellDialect()
|
||||||
.getFileCopyCommand(proc.getOsType().normalizeFileName(file), proc.getOsType().normalizeFileName(newFile))).complex()
|
.getFileCopyCommand(file, newFile)).complex()
|
||||||
.start()) {
|
.start()) {
|
||||||
pc.discardOrThrow();
|
pc.discardOrThrow();
|
||||||
}
|
}
|
||||||
|
@ -98,7 +100,7 @@ public class ConnectionFileSystem implements FileSystem {
|
||||||
@Override
|
@Override
|
||||||
public void move(String file, String newFile) throws Exception {
|
public void move(String file, String newFile) throws Exception {
|
||||||
try (var pc = shellControl.command(proc -> proc.getShellDialect()
|
try (var pc = shellControl.command(proc -> proc.getShellDialect()
|
||||||
.getFileMoveCommand(proc.getOsType().normalizeFileName(file), proc.getOsType().normalizeFileName(newFile))).complex()
|
.getFileMoveCommand(file, newFile)).complex()
|
||||||
.start()) {
|
.start()) {
|
||||||
pc.discardOrThrow();
|
pc.discardOrThrow();
|
||||||
}
|
}
|
||||||
|
@ -107,7 +109,7 @@ public class ConnectionFileSystem implements FileSystem {
|
||||||
@Override
|
@Override
|
||||||
public boolean mkdirs(String file) throws Exception {
|
public boolean mkdirs(String file) throws Exception {
|
||||||
try (var pc = shellControl.command(proc -> proc.getShellDialect()
|
try (var pc = shellControl.command(proc -> proc.getShellDialect()
|
||||||
.getMkdirsCommand(proc.getOsType().normalizeFileName(file))).complex()
|
.getMkdirsCommand(file)).complex()
|
||||||
.start()) {
|
.start()) {
|
||||||
return pc.discardAndCheckExit();
|
return pc.discardAndCheckExit();
|
||||||
}
|
}
|
||||||
|
@ -116,7 +118,7 @@ public class ConnectionFileSystem implements FileSystem {
|
||||||
@Override
|
@Override
|
||||||
public void touch(String file) throws Exception {
|
public void touch(String file) throws Exception {
|
||||||
try (var pc = shellControl.command(proc -> proc.getShellDialect()
|
try (var pc = shellControl.command(proc -> proc.getShellDialect()
|
||||||
.getFileTouchCommand(proc.getOsType().normalizeFileName(file))).complex()
|
.getFileTouchCommand(file)).complex()
|
||||||
.start()) {
|
.start()) {
|
||||||
pc.discardOrThrow();
|
pc.discardOrThrow();
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ public interface FileSystem extends Closeable, AutoCloseable {
|
||||||
|
|
||||||
void touch(String file) throws Exception;
|
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;
|
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