Merge pull request #6907 from eed3si9n/bport/6887

[1.7.x] Use XDG_RUNTIME_DIR environment variable to choose the path used for the creation of sockets
This commit is contained in:
eugene yokota 2022-05-29 01:51:37 -04:00 committed by GitHub
commit 1b4b9f3618
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 5 deletions

View File

@ -284,10 +284,11 @@ public class BootServerSocket implements AutoCloseable {
public BootServerSocket(final AppConfiguration configuration)
throws ServerAlreadyBootingException, IOException {
final Path base = configuration.baseDirectory().toPath().toRealPath();
final Path target = base.resolve("project").resolve("target");
if (!isWindows) {
final String actualSocketLocation = socketLocation(base);
final Path target = Paths.get(actualSocketLocation).getParent();
if (!Files.isDirectory(target)) Files.createDirectories(target);
socketFile = Paths.get(socketLocation(base));
socketFile = Paths.get(actualSocketLocation);
} else {
socketFile = null;
}
@ -301,13 +302,20 @@ public class BootServerSocket implements AutoCloseable {
}
}
public static String socketLocation(final Path base) throws UnsupportedEncodingException {
public static String socketLocation(final Path base)
throws UnsupportedEncodingException, IOException {
final Path target = base.resolve("project").resolve("target");
long hash = LongHashFunction.farmNa().hashBytes(target.toString().getBytes("UTF-8"));
if (isWindows) {
long hash = LongHashFunction.farmNa().hashBytes(target.toString().getBytes("UTF-8"));
return "sbt-load" + hash;
} else {
return base.relativize(target.resolve("sbt-load.sock")).toString();
final String alternativeSocketLocation =
System.getenv().getOrDefault("XDG_RUNTIME_DIR", "/tmp");
final Path alternativeSocketLocationRoot =
Paths.get(alternativeSocketLocation).resolve(".sbt");
final Path locationForSocket = alternativeSocketLocationRoot.resolve("sbt-socket" + hash);
final Path pathForSocket = locationForSocket.resolve("sbt-load.sock");
return pathForSocket.toString();
}
}