Temp fixes

This commit is contained in:
crschnick 2024-03-24 03:32:39 +00:00
parent 57352b566f
commit a44594ef5f

View file

@ -17,7 +17,8 @@ public class ShellTemp {
public static Path getLocalTempDataDirectory(String sub) { public static Path getLocalTempDataDirectory(String sub) {
var temp = FileUtils.getTempDirectory().toPath().resolve("xpipe"); var temp = FileUtils.getTempDirectory().toPath().resolve("xpipe");
// On macOS, we already have user specific temp directories // On Windows and macOS, we already have user specific temp directories
// Even on macOS as root we will have a unique directory (in contrast to shell controls)
if (OsType.getLocal().equals(OsType.LINUX)) { if (OsType.getLocal().equals(OsType.LINUX)) {
var user = System.getenv("USER"); var user = System.getenv("USER");
temp = temp.resolve(user != null ? user : "user"); temp = temp.resolve(user != null ? user : "user");
@ -35,17 +36,16 @@ public class ShellTemp {
public static String getUserSpecificTempDataDirectory(ShellControl proc, String sub) throws Exception { public static String getUserSpecificTempDataDirectory(ShellControl proc, String sub) throws Exception {
String base; String base;
if (OsType.getLocal() != OsType.WINDOWS) { // On Windows and macOS, we already have user specific temp directories
base = FileNames.join("/tmp", "xpipe"); // Even on macOS as root it is technically unique as only root will use /tmp
if (!proc.getOsType().equals(OsType.WINDOWS) && !proc.getOsType().equals(OsType.MACOS)) {
var temp = proc.getSystemTemporaryDirectory();
base = FileNames.join(temp, "xpipe");
// We have to make sure that also other users can create files here // We have to make sure that also other users can create files here
// This command should work in all shells on unix systems // This command should work in all shells
proc.command("chmod 777 " + proc.getShellDialect().fileArgument(base)) proc.command("chmod 777 " + proc.getShellDialect().fileArgument(base)).executeAndCheck();
.executeAndCheck(); var user = proc.getShellDialect().printUsernameCommand(proc).readStdoutOrThrow();
// Use user-specific directories on anything else than macOS as that one already has that base = FileNames.join(base, user);
if (!proc.getOsType().equals(OsType.MACOS)) {
var user = proc.getShellDialect().printUsernameCommand(proc).readStdoutOrThrow();
base = FileNames.join(base, user);
}
} else { } else {
var temp = proc.getSystemTemporaryDirectory(); var temp = proc.getSystemTemporaryDirectory();
base = FileNames.join(temp, "xpipe"); base = FileNames.join(temp, "xpipe");
@ -56,7 +56,7 @@ public class ShellTemp {
public static void checkTempDirectory(ShellControl proc) throws Exception { public static void checkTempDirectory(ShellControl proc) throws Exception {
var d = proc.getShellDialect(); var d = proc.getShellDialect();
var systemTemp = proc.getOsType().getTempDirectory(proc); var systemTemp = proc.getSystemTemporaryDirectory();
if (!d.directoryExists(proc, systemTemp).executeAndCheck() || !checkDirectoryPermissions(proc, systemTemp)) { if (!d.directoryExists(proc, systemTemp).executeAndCheck() || !checkDirectoryPermissions(proc, systemTemp)) {
throw ErrorEvent.expected(new IOException("No permissions to access %s".formatted(systemTemp))); throw ErrorEvent.expected(new IOException("No permissions to access %s".formatted(systemTemp)));
} }