Skip to content

Commit

Permalink
Mask forward slashes in cross values to fix their cache locations (#2986
Browse files Browse the repository at this point in the history
)

Fix: #2835

Pull request: #2986
  • Loading branch information
lefou authored Jan 23, 2024
1 parent 5793eee commit 8b99dd0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion main/eval/src/mill/eval/EvaluatorPaths.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ object EvaluatorPaths {
private val Colon = "[:]".r
// Dollar sign `$` is our masking-character
private val Dollar = "[$]".r
// Forward-slashed are reserved for directory delimiters
private val Slash = "/".r

private val steps: Seq[String => String] = Seq(
// Step 1: mask all existing dollar signs, so we can use the dollar as masking character
Expand All @@ -63,7 +65,9 @@ object EvaluatorPaths {
case s => s
},
// Step 3: Replace colon (:) with $colon
s => Colon.replaceAllIn(s, Matcher.quoteReplacement("$colon"))
s => Colon.replaceAllIn(s, Matcher.quoteReplacement("$colon")),
// Step 4: Replace slash (/) with $slash
s => Slash.replaceAllIn(s, Matcher.quoteReplacement("$slash"))
)

def sanitizePathSegment(segment: String): os.PathChunk = {
Expand Down
6 changes: 4 additions & 2 deletions main/eval/test/src/mill/eval/EvaluatorPathsTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object EvaluatorPathsTests extends TestSuite {

override def tests: Tests = Tests {
"sanitizedPathSegment" - {
"WindowsReservedNames" - {
"mask-reserved-chars-and-names" - {
val replace = Seq(
// reserved file names under Windows
"com1.json" -> "com1~.json",
Expand All @@ -16,7 +16,9 @@ object EvaluatorPathsTests extends TestSuite {
// do not collide with the applied `$`-masking character
"a$colonb" -> "a$$colonb",
// replace not just the first $
"a$$b" -> "a$$$$b"
"a$$b" -> "a$$$$b",
// replace a forward slash,
"a/b" -> "a$slashb"
)
val noReplace = Seq(
"con10.json"
Expand Down

0 comments on commit 8b99dd0

Please sign in to comment.