mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-09-30 00:56:56 +13:00
Temp fixes
This commit is contained in:
parent
57352b566f
commit
a44594ef5f
1 changed files with 12 additions and 12 deletions
|
@ -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)));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue