Skip to content

Commit

Permalink
fix for 2743
Browse files Browse the repository at this point in the history
  • Loading branch information
philwalk committed Feb 20, 2024
1 parent 2c61e87 commit 3f1faeb
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions modules/cli/src/main/scala/scala/cli/packaging/NativeImage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,24 @@ object NativeImage {
res.exitCode
}

private lazy val mountedDrives: String = {
val str = "HKEY_LOCAL_MACHINE/SYSTEM/MountedDevices".replace('/', '\\')
val queryDrives = s"reg query $str"
val lines = os.proc("cmd", "/c", queryDrives).call().out.lines()
val dosDevices = lines.filter { s =>
s.contains("DosDevices")
}.map { s =>
s.replaceAll(".DosDevices.", "").replaceAll(":.*", "")
}
dosDevices.mkString
}
private def availableDriveLetter(): Char = {

@tailrec
def helper(from: Char): Char =
if (from > 'Z') sys.error("Cannot find free drive letter")
else {
val p = os.Path(s"$from:" + "\\")
if (os.exists(p)) helper((from + 1).toChar)
if (mountedDrives.contains(from)) helper((from + 1).toChar)
else from
}

Expand Down

0 comments on commit 3f1faeb

Please sign in to comment.