More temporary directory fixes

This commit is contained in:
crschnick 2023-05-22 21:23:05 +00:00
parent 442f8f7324
commit b171dd099c
5 changed files with 17 additions and 11 deletions

View file

@ -42,7 +42,7 @@ public class AppInstaller {
targetFile = localFile.toString(); targetFile = localFile.toString();
} else { } else {
targetFile = FileNames.join( targetFile = FileNames.join(
s.getTemporaryDirectory(), localFile.getFileName().toString()); s.getSubTemporaryDirectory(), localFile.getFileName().toString());
try (InputStream in = Files.newInputStream(localFile)) { try (InputStream in = Files.newInputStream(localFile)) {
in.transferTo(s.getShellDialect().createStreamFileWriteCommand(s, targetFile).startExternalStdin()); in.transferTo(s.getShellDialect().createStreamFileWriteCommand(s, targetFile).startExternalStdin());
} }

View file

@ -10,7 +10,6 @@ import io.xpipe.core.process.ShellDialects;
import io.xpipe.core.util.SecretValue; import io.xpipe.core.util.SecretValue;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@ -84,7 +83,7 @@ public class ScriptHelper {
@SneakyThrows @SneakyThrows
public static String getExecScriptFile(ShellControl processControl, String fileEnding) { public static String getExecScriptFile(ShellControl processControl, String fileEnding) {
var fileName = "exec-" + getScriptId(); var fileName = "exec-" + getScriptId();
var temp = processControl.getTemporaryDirectory(); var temp = processControl.getSubTemporaryDirectory();
var file = FileNames.join(temp, fileName + "." + fileEnding); var file = FileNames.join(temp, fileName + "." + fileEnding);
return file; return file;
} }
@ -93,7 +92,7 @@ public class ScriptHelper {
public static String createExecScript(ShellControl processControl, String content) { public static String createExecScript(ShellControl processControl, String content) {
var fileName = "exec-" + getScriptId(); var fileName = "exec-" + getScriptId();
ShellDialect type = processControl.getShellDialect(); ShellDialect type = processControl.getShellDialect();
var temp = processControl.getTemporaryDirectory(); var temp = processControl.getSubTemporaryDirectory();
var file = FileNames.join(temp, fileName + "." + type.getScriptFileEnding()); var file = FileNames.join(temp, fileName + "." + type.getScriptFileEnding());
return createExecScript(processControl, file, content); return createExecScript(processControl, file, content);
} }
@ -122,6 +121,11 @@ public class ScriptHelper {
public static String createAskPassScript(SecretValue pass, ShellControl parent, boolean forceExecutable) public static String createAskPassScript(SecretValue pass, ShellControl parent, boolean forceExecutable)
throws Exception { throws Exception {
return createAskPassScript(pass != null ? List.of(pass) : List.of(), parent, forceExecutable);
}
public static String createAskPassScript(List<SecretValue> pass, ShellControl parent, boolean forceExecutable)
throws Exception {
var scriptType = parent.getShellDialect(); var scriptType = parent.getShellDialect();
// Fix for powershell as there are permission issues when executing a powershell askpass script // Fix for powershell as there are permission issues when executing a powershell askpass script
@ -132,23 +136,23 @@ public class ScriptHelper {
return createAskPassScript(pass, parent, scriptType); return createAskPassScript(pass, parent, scriptType);
} }
private static String createAskPassScript(SecretValue pass, ShellControl parent, ShellDialect type) private static String createAskPassScript(List<SecretValue> pass, ShellControl parent, ShellDialect type)
throws Exception { throws Exception {
var fileName = "askpass-" + getScriptId() + "." + type.getScriptFileEnding(); var fileName = "askpass-" + getScriptId() + "." + type.getScriptFileEnding();
var temp = parent.getTemporaryDirectory(); var temp = parent.getSubTemporaryDirectory();
var file = FileNames.join(temp, fileName); var file = FileNames.join(temp, fileName);
if (type != parent.getShellDialect()) { if (type != parent.getShellDialect()) {
try (var sub = parent.subShell(type).start()) { try (var sub = parent.subShell(type).start()) {
var content = sub.getShellDialect() var content = sub.getShellDialect()
.prepareAskpassContent( .prepareAskpassContent(
sub, file, pass != null ? Collections.singletonList(pass.getSecretValue()) : List.of()); sub, file, pass.stream().map(secretValue -> secretValue.getSecretValue()).toList());
var exec = createExecScript(sub, file, content); var exec = createExecScript(sub, file, content);
return exec; return exec;
} }
} else { } else {
var content = parent.getShellDialect() var content = parent.getShellDialect()
.prepareAskpassContent( .prepareAskpassContent(
parent, file, pass != null ? Collections.singletonList(pass.getSecretValue()) : List.of()); parent, file, pass.stream().map(secretValue -> secretValue.getSecretValue()).toList());
var exec = createExecScript(parent, file, content); var exec = createExecScript(parent, file, content);
return exec; return exec;
} }

View file

@ -33,7 +33,9 @@ public interface ShellControl extends ProcessControl {
String prepareIntermediateTerminalOpen(String content, String displayName) throws Exception; String prepareIntermediateTerminalOpen(String content, String displayName) throws Exception;
String getTemporaryDirectory() throws Exception; String getSystemTemporaryDirectory();
String getSubTemporaryDirectory();
public void checkRunning() throws Exception; public void checkRunning() throws Exception;

View file

@ -110,7 +110,7 @@ public interface ShellDialect {
String prepareTerminalInitFileOpenCommand(ShellDialect parentDialect, ShellControl sc, String file) throws Exception; String prepareTerminalInitFileOpenCommand(ShellDialect parentDialect, ShellControl sc, String file) throws Exception;
String runScript(String file); String runScript(ShellControl parent, String file);
String sourceScript(String file); String sourceScript(String file);

View file

@ -61,6 +61,6 @@ public class RunAction extends MultiExecuteAction {
@Override @Override
protected String createCommand(ShellControl sc, OpenFileSystemModel model, BrowserEntry entry) { protected String createCommand(ShellControl sc, OpenFileSystemModel model, BrowserEntry entry) {
return sc.getShellDialect().runScript(entry.getFileName()); return sc.getShellDialect().runScript(sc, entry.getFileName());
} }
} }