mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-25 09:00:26 +00:00
Improve working directory handling if it does not exist
This commit is contained in:
parent
50defba23d
commit
cde12be5c8
2 changed files with 32 additions and 1 deletions
|
@ -3,7 +3,9 @@ package io.xpipe.app.util;
|
||||||
import io.xpipe.beacon.ClientException;
|
import io.xpipe.beacon.ClientException;
|
||||||
import io.xpipe.beacon.ServerException;
|
import io.xpipe.beacon.ServerException;
|
||||||
import io.xpipe.core.process.ProcessControl;
|
import io.xpipe.core.process.ProcessControl;
|
||||||
|
import io.xpipe.core.process.ShellControl;
|
||||||
import io.xpipe.core.process.TerminalInitScriptConfig;
|
import io.xpipe.core.process.TerminalInitScriptConfig;
|
||||||
|
import io.xpipe.core.util.FailableFunction;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.Value;
|
import lombok.Value;
|
||||||
import lombok.experimental.NonFinal;
|
import lombok.experimental.NonFinal;
|
||||||
|
@ -20,9 +22,21 @@ public class TerminalLauncherManager {
|
||||||
|
|
||||||
private static void prepare(
|
private static void prepare(
|
||||||
ProcessControl processControl, TerminalInitScriptConfig config, String directory, Entry entry) {
|
ProcessControl processControl, TerminalInitScriptConfig config, String directory, Entry entry) {
|
||||||
|
FailableFunction<ShellControl, String, Exception> workingDirectory = sc -> {
|
||||||
|
if (directory == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sc.getShellDialect().directoryExists(sc,directory).executeAndCheck()) {
|
||||||
|
return sc.getOsType().getFallbackWorkingDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
return directory;
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var file = ScriptHelper.createLocalExecScript(
|
var file = ScriptHelper.createLocalExecScript(
|
||||||
processControl.prepareTerminalOpen(config, directory != null ? var1 -> directory : null));
|
processControl.prepareTerminalOpen(config, workingDirectory));
|
||||||
entry.setResult(new ResultSuccess(Path.of(file)));
|
entry.setResult(new ResultSuccess(Path.of(file)));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
entry.setResult(new ResultFailure(e));
|
entry.setResult(new ResultFailure(e));
|
||||||
|
|
|
@ -28,6 +28,8 @@ public interface OsType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getFallbackWorkingDirectory();
|
||||||
|
|
||||||
List<String> determineInterestingPaths(ShellControl pc) throws Exception;
|
List<String> determineInterestingPaths(ShellControl pc) throws Exception;
|
||||||
|
|
||||||
String getHomeDirectory(ShellControl pc) throws Exception;
|
String getHomeDirectory(ShellControl pc) throws Exception;
|
||||||
|
@ -54,6 +56,11 @@ public interface OsType {
|
||||||
|
|
||||||
final class Windows implements OsType, Local, Any {
|
final class Windows implements OsType, Local, Any {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFallbackWorkingDirectory() {
|
||||||
|
return "C:\\";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> determineInterestingPaths(ShellControl pc) throws Exception {
|
public List<String> determineInterestingPaths(ShellControl pc) throws Exception {
|
||||||
var home = getHomeDirectory(pc);
|
var home = getHomeDirectory(pc);
|
||||||
|
@ -116,6 +123,11 @@ public interface OsType {
|
||||||
|
|
||||||
class Unix implements OsType {
|
class Unix implements OsType {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFallbackWorkingDirectory() {
|
||||||
|
return "/";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> determineInterestingPaths(ShellControl pc) throws Exception {
|
public List<String> determineInterestingPaths(ShellControl pc) throws Exception {
|
||||||
var home = getHomeDirectory(pc);
|
var home = getHomeDirectory(pc);
|
||||||
|
@ -198,6 +210,11 @@ public interface OsType {
|
||||||
|
|
||||||
final class MacOs implements OsType, Local, Any {
|
final class MacOs implements OsType, Local, Any {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFallbackWorkingDirectory() {
|
||||||
|
return "/";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> determineInterestingPaths(ShellControl pc) throws Exception {
|
public List<String> determineInterestingPaths(ShellControl pc) throws Exception {
|
||||||
var home = getHomeDirectory(pc);
|
var home = getHomeDirectory(pc);
|
||||||
|
|
Loading…
Reference in a new issue