Fixes for subshell elevation

This commit is contained in:
crschnick 2024-05-16 13:56:41 +00:00
parent b36ca8f557
commit 856322e052
2 changed files with 32 additions and 1 deletions

View file

@ -4,6 +4,34 @@ import io.xpipe.core.util.FailableFunction;
public interface ElevationFunction {
static ElevationFunction ifNotRoot(ElevationFunction function) {
return new ElevationFunction() {
@Override
public String getPrefix() {
return function.getPrefix();
}
@Override
public boolean isSpecified() {
return true;
}
@Override
public boolean apply(ShellControl shellControl) throws Exception {
if (shellControl.getOsType() == OsType.WINDOWS) {
return false;
}
var isRoot = shellControl.executeSimpleBooleanCommand("test \"${EUID:-$(id -u)}\" -eq 0");
if (isRoot) {
return false;
}
return function.apply(shellControl);
}
};
}
static ElevationFunction of(String prefix, FailableFunction<ShellControl, Boolean, Exception> f) {
return new ElevationFunction() {
@Override

View file

@ -207,7 +207,10 @@ public interface ShellControl extends ProcessControl {
return CommandBuilder.ofString(command);
}
};
return singularSubShell(o);
var sc = singularSubShell(o);
sc.withSourceStore(getSourceStore().orElse(null));
sc.setParentSystemAccess(ParentSystemAccess.identity());
return sc;
}
default <T> T enforceDialect(@NonNull ShellDialect type, FailableFunction<ShellControl, T, Exception> sc)