Skip to content

Commit

Permalink
Don't call directories-jvm stuff if BLOOP_DAEMON_DIR is set (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault authored Dec 15, 2021
1 parent d33292e commit 13df81f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
37 changes: 22 additions & 15 deletions bloopgun-core/src/main/scala/bloop/bloopgun/Defaults.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,30 @@ object Defaults {
}

// also more or less in bloop.io.Paths…
private val projectDirectories = ProjectDirectories.from("", "", "bloop")
private final val bloopCacheDir: Path = Paths.get(projectDirectories.cacheDir)
private final val bloopDataDir: Path = Paths.get(projectDirectories.dataDir)
private lazy val projectDirectories = ProjectDirectories.from("", "", "bloop")
private lazy val bloopCacheDir: Path = Paths.get(projectDirectories.cacheDir)
private lazy val bloopDataDir: Path = Paths.get(projectDirectories.dataDir)

final val daemonDir: Path = {
val baseDir =
if (Properties.isMac) bloopCacheDir
else bloopDataDir
val dir = baseDir.resolve("daemon")
Files.createDirectories(dir)
if (!Properties.isWin) {
Files.setPosixFilePermissions(
dir,
PosixFilePermissions.fromString("rwx------")
)
lazy val daemonDir: Path = {
def defaultDir = {
val baseDir =
if (Properties.isMac) bloopCacheDir
else bloopDataDir
baseDir.resolve("daemon")
}
val dir = Option(System.getenv("BLOOP_DAEMON_DIR")).filter(_.trim.nonEmpty) match {
case Some(dirStr) => Paths.get(dirStr)
case None => defaultDir
}
if (!Files.exists(dir)) {
Files.createDirectories(dir)
if (!Properties.isWin)
Files.setPosixFilePermissions(
dir,
PosixFilePermissions.fromString("rwx------")
)
}
dir
}
final val daemonPipeName: String = "scala_bloop_server"
def daemonPipeName: String = "scala_bloop_server"
}
40 changes: 21 additions & 19 deletions shared/src/main/scala/bloop/io/Paths.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,35 @@ import java.nio.file.NoSuchFileException
import scala.util.Properties

object Paths {
private val projectDirectories = ProjectDirectories.from("", "", "bloop")
private lazy val projectDirectories = ProjectDirectories.from("", "", "bloop")
private def createDirFor(filepath: String): AbsolutePath =
AbsolutePath(Files.createDirectories(NioPaths.get(filepath)))

final val bloopCacheDir: AbsolutePath = createDirFor(projectDirectories.cacheDir)
final val bloopDataDir: AbsolutePath = createDirFor(projectDirectories.dataDir)
final val bloopLogsDir: AbsolutePath = createDirFor(bloopDataDir.resolve("logs").syntax)
final val bloopConfigDir: AbsolutePath = createDirFor(projectDirectories.configDir)

final val daemonDir: AbsolutePath = {
val baseDir =
if (Properties.isMac) bloopCacheDir
else bloopDataDir
val dir = baseDir.resolve("daemon")
if (!Files.exists(dir.underlying)) {
Files.createDirectories(dir.underlying)
if (!Properties.isWin) {
private lazy val bloopCacheDir: AbsolutePath = createDirFor(projectDirectories.cacheDir)
private lazy val bloopDataDir: AbsolutePath = createDirFor(projectDirectories.dataDir)

lazy val daemonDir: AbsolutePath = {
def defaultDir = {
val baseDir =
if (Properties.isMac) bloopCacheDir.underlying
else bloopDataDir.underlying
baseDir.resolve("daemon")
}
val dir = Option(System.getenv("BLOOP_DAEMON_DIR")).filter(_.trim.nonEmpty) match {
case Some(dirStr) => java.nio.file.Paths.get(dirStr)
case None => defaultDir
}
if (!Files.exists(dir)) {
Files.createDirectories(dir)
if (!Properties.isWin)
Files.setPosixFilePermissions(
dir.underlying,
dir,
PosixFilePermissions.fromString("rwx------")
)
}
}
dir
AbsolutePath(dir)
}

final val pipeName: String = "scala_bloop_server"
def pipeName: String = "scala_bloop_server"

def getCacheDirectory(dirName: String): AbsolutePath = {
val dir = bloopCacheDir.resolve(dirName)
Expand Down

0 comments on commit 13df81f

Please sign in to comment.