Merge pull request #6935 from eed3si9n/wip/temp-directories

[1.7.x] Fix sbt trying to delete /tmp on ARM Macs
This commit is contained in:
eugene yokota 2022-06-25 20:23:39 -04:00 committed by GitHub
commit 1db7dd328a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 5 deletions

View File

@ -310,7 +310,7 @@ public class BootServerSocket implements AutoCloseable {
return "sbt-load" + hash;
} else {
final String alternativeSocketLocation =
System.getenv().getOrDefault("XDG_RUNTIME_DIR", "/tmp");
System.getenv().getOrDefault("XDG_RUNTIME_DIR", System.getProperty("java.io.tmpdir"));
final Path alternativeSocketLocationRoot =
Paths.get(alternativeSocketLocation).resolve(".sbt");
final Path locationForSocket = alternativeSocketLocationRoot.resolve("sbt-socket" + hash);

View File

@ -101,10 +101,8 @@ private[sbt] object Load {
val delegates = defaultDelegates
val pluginMgmt = PluginManagement(loader)
val inject = InjectSettings(injectGlobal(state), Nil, const(Nil))
System.setProperty(
"swoval.tmpdir",
System.getProperty("swoval.tmpdir", globalBase.getAbsolutePath.toString)
)
SysProp.setSwovalTempDir()
SysProp.setIpcSocketTempDir()
LoadBuildConfiguration(
stagingDirectory,
classpath,

View File

@ -9,6 +9,7 @@ package sbt
package internal
import java.io.File
import java.nio.file.{ Path, Paths }
import java.util.Locale
import scala.util.control.NonFatal
@ -220,4 +221,33 @@ object SysProp {
lazy val sbtCredentialsEnv: Option[Credentials] =
sys.env.get("SBT_CREDENTIALS").map(raw => new FileCredentials(new File(raw)))
private[sbt] def setSwovalTempDir(): Unit = {
val _ = getOrUpdateSwovalTmpDir(
runtimeDirectory.resolve("swoval").toString
)
}
private[sbt] def setIpcSocketTempDir(): Unit = {
val _ = getOrUpdateIpcSocketTmpDir(
runtimeDirectory.resolve("ipcsocket").toString
)
}
private[this] lazy val getOrUpdateSwovalTmpDir: String => String =
getOrUpdateSysProp("swoval.tmpdir")(_)
private[this] lazy val getOrUpdateIpcSocketTmpDir: String => String =
getOrUpdateSysProp("sbt.ipcsocket.tmpdir")(_)
private[this] def getOrUpdateSysProp(key: String)(value: String): String = {
val newVal = sys.props.getOrElse(key, value)
sys.props += (key -> newVal)
newVal
}
/**
* This returns a temporary directory that is friendly to macOS, Linux,
* Windows, and Docker environment.
* Mostly these directories will be used as throw-away location to extract
* native files etc.
*/
private[this] def runtimeDirectory: Path =
Paths.get(sys.env.getOrElse("XDG_RUNTIME_DIR", sys.props("java.io.tmpdir"))).resolve(".sbt")
}