Various fixes [stage]

This commit is contained in:
crschnick
2023-05-30 01:59:08 +00:00
parent 52cdcfa0aa
commit daa011ffe6
24 changed files with 380 additions and 92 deletions

View File

@@ -53,7 +53,11 @@ public sealed interface OsType permits OsType.Windows, OsType.Linux, OsType.MacO
@Override
public List<String> determineInterestingPaths(ShellControl pc) throws Exception {
var home = getHomeDirectory(pc);
return List.of(home, FileNames.join(home, "Documents"), FileNames.join(home, "Downloads"), FileNames.join(home, "Desktop"));
return List.of(
home,
FileNames.join(home, "Documents"),
FileNames.join(home, "Downloads"),
FileNames.join(home, "Desktop"));
}
@Override
@@ -111,7 +115,8 @@ public sealed interface OsType permits OsType.Windows, OsType.Linux, OsType.MacO
@Override
public List<String> determineInterestingPaths(ShellControl pc) throws Exception {
var home = getHomeDirectory(pc);
return List.of(FileNames.join(home, "Desktop"));
return List.of(
home, FileNames.join(home, "Downloads"), FileNames.join(home, "Documents"), "/etc", "/tmp", "/var");
}
@Override
@@ -180,7 +185,16 @@ public sealed interface OsType permits OsType.Windows, OsType.Linux, OsType.MacO
@Override
public List<String> determineInterestingPaths(ShellControl pc) throws Exception {
var home = getHomeDirectory(pc);
return List.of(FileNames.join(home, "Desktop"));
return List.of(
home,
FileNames.join(home, "Downloads"),
FileNames.join(home, "Documents"),
FileNames.join(home, "Desktop"),
"/Applications",
"/Library",
"/System",
"/etc"
);
}
@Override

View File

@@ -6,35 +6,40 @@ import lombok.Getter;
public class ProcessOutputException extends Exception {
public static ProcessOutputException of(String customPrefix, ProcessOutputException ex) {
var messageSuffix = ex.getOutput() != null && ! ex.getOutput().isBlank()?": " + ex.getOutput() : "";
var messageSuffix = ex.getOutput() != null && !ex.getOutput().isBlank() ? ": " + ex.getOutput() : "";
var message = customPrefix + messageSuffix;
return new ProcessOutputException(message, ex.getExitCode(), ex.getOutput());
}
public static ProcessOutputException of(int exitCode, String output, String accumulatedError) {
var combinedError = (accumulatedError != null ? accumulatedError.trim() + "\n" : "") + (output != null ? output.trim() : "");
var message = switch (exitCode) {
case CommandControl.KILLED_EXIT_CODE -> "Process timed out (exit code " + exitCode + ") " + combinedError;
case CommandControl.TIMEOUT_EXIT_CODE -> "Process timed out (exit code " + exitCode + ") " + combinedError;
default -> "Process returned with exit code " + exitCode + ": " + combinedError;
};
var combinedError = (accumulatedError != null ? accumulatedError.trim() + "\n" : "")
+ (output != null ? output.trim() : "");
var hasMessage = !combinedError.trim().isEmpty();
var errorSuffix = hasMessage ? ": " + combinedError : "";
var message =
switch (exitCode) {
case CommandControl.KILLED_EXIT_CODE -> "Process timed out and had to be killed" + errorSuffix;
case CommandControl.TIMEOUT_EXIT_CODE -> "Wait for process exit timed out"
+ errorSuffix;
default -> "Process returned exit code " + exitCode + errorSuffix;
};
return new ProcessOutputException(message, exitCode, combinedError);
}
private final int exitCode;
private final String output;
private ProcessOutputException(String message, int exitCode, String output) {
private ProcessOutputException(String message, int exitCode, String output) {
super(message);
this.exitCode = exitCode;
this.output = output;
}
public boolean isTimeOut() {
return exitCode == CommandControl.TIMEOUT_EXIT_CODE;
return exitCode == CommandControl.TIMEOUT_EXIT_CODE;
}
public boolean isKill() {
return exitCode == CommandControl.KILLED_EXIT_CODE;
return exitCode == CommandControl.KILLED_EXIT_CODE;
}
}