From f2bf943d564e235681108a454cff5b86a9f18bfd Mon Sep 17 00:00:00 2001 From: crschnick Date: Sat, 11 Mar 2023 01:33:02 +0000 Subject: [PATCH] Shell fixes --- .../main/java/io/xpipe/app/update/AppInstaller.java | 12 ++---------- .../java/io/xpipe/app/util/DesktopShortcuts.java | 4 ++-- .../main/java/io/xpipe/app/util/ScriptHelper.java | 2 +- .../java/io/xpipe/core/process/CommandControl.java | 8 ++++++++ .../java/io/xpipe/core/process/ShellDialect.java | 6 +++--- .../io/xpipe/core/store/ConnectionFileSystem.java | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/update/AppInstaller.java b/app/src/main/java/io/xpipe/app/update/AppInstaller.java index b869e672..aed04600 100644 --- a/app/src/main/java/io/xpipe/app/update/AppInstaller.java +++ b/app/src/main/java/io/xpipe/app/update/AppInstaller.java @@ -43,17 +43,9 @@ public class AppInstaller { } else { targetFile = FileNames.join( s.getTemporaryDirectory(), localFile.getFileName().toString()); - try (CommandControl c = s.getShellDialect().getStreamFileWriteCommand(s, targetFile) - .start()) { - c.discardOut(); - c.discardErr(); - try (InputStream in = Files.newInputStream(localFile)) { - in.transferTo(c.getStdin()); - } - c.closeStdin(); + try (InputStream in = Files.newInputStream(localFile)) { + in.transferTo(s.getShellDialect().createStreamFileWriteCommand(s, targetFile).startExternalStdin()); } - - s.restart(); } asset.installRemote(s, targetFile); diff --git a/app/src/main/java/io/xpipe/app/util/DesktopShortcuts.java b/app/src/main/java/io/xpipe/app/util/DesktopShortcuts.java index c94060c6..e2ab15b7 100644 --- a/app/src/main/java/io/xpipe/app/util/DesktopShortcuts.java +++ b/app/src/main/java/io/xpipe/app/util/DesktopShortcuts.java @@ -60,10 +60,10 @@ public class DesktopShortcuts { pc.getShellDialect().flatten(pc.getShellDialect().getMkdirsCommand(base + "/Contents/Resources"))); var executable = base + "/Contents/MacOS/" + name; - pc.executeSimpleCommand(pc.getShellDialect().getTextFileWriteCommand(content, executable)); + pc.getShellDialect().createTextFileWriteCommand(pc, content, executable).execute(); pc.executeSimpleCommand("chmod ugo+x \"" + executable + "\""); - pc.executeSimpleCommand(pc.getShellDialect().getTextFileWriteCommand("APPL????", base + "/PkgInfo")); + pc.getShellDialect().createTextFileWriteCommand(pc, "APPL????", base + "/PkgInfo").execute(); pc.executeSimpleCommand("cp \"" + icon + "\" \"" + base + "/Contents/Resources/" + name + ".icns\""); } } diff --git a/app/src/main/java/io/xpipe/app/util/ScriptHelper.java b/app/src/main/java/io/xpipe/app/util/ScriptHelper.java index 41bb3850..6529186a 100644 --- a/app/src/main/java/io/xpipe/app/util/ScriptHelper.java +++ b/app/src/main/java/io/xpipe/app/util/ScriptHelper.java @@ -200,7 +200,7 @@ public class ScriptHelper { .handle(); // processControl.executeSimpleCommand(type.getFileTouchCommand(file), "Failed to create script " + file); - processControl.executeSimpleCommand(type.getTextFileWriteCommand(content, file)); + processControl.getShellDialect().createTextFileWriteCommand(processControl, content, file).execute(); processControl.executeSimpleCommand( type.getMakeExecutableCommand(file), "Failed to make script " + file + " executable"); return file; 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 b0f8d261..a1aa4161 100644 --- a/core/src/main/java/io/xpipe/core/process/CommandControl.java +++ b/core/src/main/java/io/xpipe/core/process/CommandControl.java @@ -26,8 +26,16 @@ public interface CommandControl extends ProcessControl { CommandControl complex(); + CommandControl notComplex(); + CommandControl workingDirectory(String directory); + default void execute() throws Exception { + try (var c = start()) { + c.discardOrThrow(); + } + } + ShellControl getParent(); InputStream startExternalStdout() throws Exception; 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 85b4f9c6..47539bbc 100644 --- a/core/src/main/java/io/xpipe/core/process/ShellDialect.java +++ b/core/src/main/java/io/xpipe/core/process/ShellDialect.java @@ -13,6 +13,8 @@ import java.util.stream.Stream; @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") public interface ShellDialect { + CommandControl createStreamFileWriteCommand(ShellControl shellControl, String file); + default String getCdCommand(String directory){ return "cd \"" + directory + "\""; } @@ -101,9 +103,7 @@ public interface ShellDialect { String getFileMoveCommand(String oldFile, String newFile); - CommandControl getStreamFileWriteCommand(ShellControl processControl, String file); - - String getTextFileWriteCommand(String content, String file); + CommandControl createTextFileWriteCommand(ShellControl parent, String content, String file); String getFileDeleteCommand(String file); 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 74e973b6..d599e863 100644 --- a/core/src/main/java/io/xpipe/core/store/ConnectionFileSystem.java +++ b/core/src/main/java/io/xpipe/core/store/ConnectionFileSystem.java @@ -64,7 +64,7 @@ public class ConnectionFileSystem implements FileSystem { @Override public OutputStream openOutput(String file) throws Exception { return shellControl.getShellDialect() - .getStreamFileWriteCommand(shellControl, shellControl.getOsType().normalizeFileName(file)) + .createStreamFileWriteCommand(shellControl, shellControl.getOsType().normalizeFileName(file)) .startExternalStdin(); }