Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mask forward slashes in cross values to fix their cache locations #2986

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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