From 88ca58441012ac6d32f088cda65d2b077b7d40d7 Mon Sep 17 00:00:00 2001 From: Christopher Schnick Date: Sun, 11 Dec 2022 11:19:12 +0100 Subject: [PATCH] More shell fixes --- .../java/io/xpipe/core/process/ProcessControl.java | 2 ++ .../io/xpipe/core/process/ShellProcessControl.java | 2 -- .../main/java/io/xpipe/core/process/ShellType.java | 2 +- .../main/java/io/xpipe/core/store/MachineStore.java | 13 +++++++++---- .../java/io/xpipe/core/util/XPipeTempDirectory.java | 6 ++++++ 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/io/xpipe/core/process/ProcessControl.java b/core/src/main/java/io/xpipe/core/process/ProcessControl.java index c814645f7..6a401e1b5 100644 --- a/core/src/main/java/io/xpipe/core/process/ProcessControl.java +++ b/core/src/main/java/io/xpipe/core/process/ProcessControl.java @@ -20,6 +20,8 @@ public interface ProcessControl extends Closeable, AutoCloseable { void writeLine(String line) throws IOException; + void write(byte[] b) throws IOException; + @Override void close() throws IOException; void kill() throws Exception; diff --git a/core/src/main/java/io/xpipe/core/process/ShellProcessControl.java b/core/src/main/java/io/xpipe/core/process/ShellProcessControl.java index 03b2b04ef..38dcf50a2 100644 --- a/core/src/main/java/io/xpipe/core/process/ShellProcessControl.java +++ b/core/src/main/java/io/xpipe/core/process/ShellProcessControl.java @@ -53,8 +53,6 @@ public interface ShellProcessControl extends ProcessControl { ShellProcessControl elevation(SecretValue value); - ShellProcessControl startTimeout(Integer timeout); - SecretValue getElevationPassword(); default ShellProcessControl subShell(@NonNull ShellType type) { diff --git a/core/src/main/java/io/xpipe/core/process/ShellType.java b/core/src/main/java/io/xpipe/core/process/ShellType.java index c85c71d40..7d20e3bcc 100644 --- a/core/src/main/java/io/xpipe/core/process/ShellType.java +++ b/core/src/main/java/io/xpipe/core/process/ShellType.java @@ -76,7 +76,7 @@ public interface ShellType { List createMkdirsCommand(String dirs); - List createFileReadCommand(String file); + String createFileReadCommand(String file); String createFileWriteCommand(String file); diff --git a/core/src/main/java/io/xpipe/core/store/MachineStore.java b/core/src/main/java/io/xpipe/core/store/MachineStore.java index 9e4ae8c35..a387682cf 100644 --- a/core/src/main/java/io/xpipe/core/store/MachineStore.java +++ b/core/src/main/java/io/xpipe/core/store/MachineStore.java @@ -11,19 +11,22 @@ public interface MachineStore extends FileSystemStore, ShellStore { @Override public default InputStream openInput(String file) throws Exception { - return create().command(proc -> proc.getShellType().flatten(proc.getShellType().createFileReadCommand(proc.getOsType().normalizeFileName(file)))) + return create().command(proc -> proc.getShellType() + .createFileReadCommand(proc.getOsType().normalizeFileName(file))) .startExternalStdout(); } @Override public default OutputStream openOutput(String file) throws Exception { - return create().command(proc -> proc.getShellType().createFileWriteCommand(proc.getOsType().normalizeFileName(file))) + return create().command(proc -> proc.getShellType() + .createFileWriteCommand(proc.getOsType().normalizeFileName(file))) .startExternalStdin(); } @Override public default boolean exists(String file) throws Exception { - try (var pc = create().command(proc -> proc.getShellType().createFileExistsCommand(proc.getOsType().normalizeFileName(file))) + try (var pc = create().command(proc -> proc.getShellType() + .createFileExistsCommand(proc.getOsType().normalizeFileName(file))) .start()) { return pc.discardAndCheckExit(); } @@ -31,7 +34,9 @@ public interface MachineStore extends FileSystemStore, ShellStore { @Override public default boolean mkdirs(String file) throws Exception { - try (var pc = create().command(proc -> proc.getShellType().flatten(proc.getShellType().createMkdirsCommand(proc.getOsType().normalizeFileName(file)))) + try (var pc = create().command(proc -> proc.getShellType() + .flatten(proc.getShellType() + .createMkdirsCommand(proc.getOsType().normalizeFileName(file)))) .start()) { return pc.discardAndCheckExit(); } diff --git a/core/src/main/java/io/xpipe/core/util/XPipeTempDirectory.java b/core/src/main/java/io/xpipe/core/util/XPipeTempDirectory.java index 2ccd8ce78..5da37d2b1 100644 --- a/core/src/main/java/io/xpipe/core/util/XPipeTempDirectory.java +++ b/core/src/main/java/io/xpipe/core/util/XPipeTempDirectory.java @@ -1,6 +1,7 @@ package io.xpipe.core.util; import io.xpipe.core.impl.FileNames; +import io.xpipe.core.process.OsType; import io.xpipe.core.process.ShellProcessControl; import io.xpipe.core.store.ShellStore; @@ -22,6 +23,11 @@ public class XPipeTempDirectory { throw new IOException("Unable to access or create temporary directory " + dir); } + if (proc.getOsType().equals(OsType.LINUX)) { + proc.executeSimpleCommand("(chmod -f 777 \"" + dir + "\" || true)"); + + } + return dir; }