From 3e5f77a8fac10ca3e43193709ef0f8a442d9742a Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Wed, 4 Sep 2024 15:00:00 -0400 Subject: [PATCH] Create temp dir unique to user --- .../org/scalasbt/ipcsocket/NativeLoader.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/scalasbt/ipcsocket/NativeLoader.java b/src/main/java/org/scalasbt/ipcsocket/NativeLoader.java index 91883a4..ae5385c 100644 --- a/src/main/java/org/scalasbt/ipcsocket/NativeLoader.java +++ b/src/main/java/org/scalasbt/ipcsocket/NativeLoader.java @@ -34,13 +34,22 @@ class NativeLoader { private static final String pid = isWindows ? "" : ManagementFactory.getRuntimeMXBean().getName().replaceAll("@.*", ""); - private static Path tmpDir() { + private static Path runtimeDir() { String prop = System.getProperty("sbt.ipcsocket.tmpdir"); - String tmp = System.getProperty("java.io.tmpdir"); if (prop != null) { return Paths.get(prop); } else { - return Paths.get(tmp).resolve(".sbt").resolve("ipcsocket"); + String runtimeDir = System.getenv("XDG_RUNTIME_DIR"); + if (runtimeDir == null) { + runtimeDir = System.getProperty("java.io.tmpdir"); + } + String home = System.getProperty("user.home"); + if (home == null) { + home = "unknown_home"; + } + return Paths.get(runtimeDir) + .resolve(".sbt" + Integer.toString(home.hashCode())) + .resolve("ipcsocket"); } } @@ -72,7 +81,7 @@ static void load() throws UnsatisfiedLinkError { final URL url = NativeLoader.class.getClassLoader().getResource(resource); if (url == null) throw new UnsatisfiedLinkError(resource + " not found on classpath"); try { - final Path base = Files.createDirectories(tmpDir()); + final Path base = Files.createDirectories(runtimeDir()); final Path output = Files.createTempFile(base, tempFilePrefix, extension); try (final InputStream in = url.openStream(); final FileChannel channel = FileChannel.open(output, StandardOpenOption.WRITE)) { @@ -131,7 +140,7 @@ private static class CleanupRunnable implements Runnable { public void run() { try { Files.walkFileTree( - tmpDir(), + runtimeDir(), new FileVisitor() { @Override public FileVisitResult preVisitDirectory(