mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-09-19 22:01:12 +00:00
Fixes for subshell elevation
This commit is contained in:
parent
b36ca8f557
commit
856322e052
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue