Path normalization for Windows + scalafmt

- CacheUrlConversion: normalize paths for comparison (forward slashes)
  and strip leading slash on Windows file URIs so cache matching works.
- Apply scalafmt to touched files.
This commit is contained in:
bitloi 2026-02-15 05:21:54 +01:00
parent afae6daea2
commit ef6968e20c
3 changed files with 26 additions and 4 deletions

View File

@ -382,7 +382,8 @@ class CoursierDependencyResolution(
.groupBy(_._1)
.view
.mapValues(_.map { case (_, pub, art, _) =>
val originalUrl = lmcoursier.internal.CacheUrlConversion.cacheFileToOriginalUrl(art.url, cache)
val originalUrl =
lmcoursier.internal.CacheUrlConversion.cacheFileToOriginalUrl(art.url, cache)
(originalUrl, pub.classifier.value, pub.ext.value)
})
.toMap

View File

@ -15,13 +15,30 @@ object CacheUrlConversion {
final val FileUrlPrefix = "file:"
final val UnconvertiblePrefix = "${CSR_CACHE}"
private def normalizePathForComparison(path: String): String =
path.replace('\\', '/')
private def normalizedFilePath(fileUrl: String): String = {
val afterPrefix = fileUrl.stripPrefix(FileUrlPrefix).replaceFirst("^/+", "/")
val withForwardSlash = normalizePathForComparison(afterPrefix)
if (
withForwardSlash.length >= 3 && withForwardSlash
.charAt(0) == '/' && withForwardSlash.charAt(2) == ':'
)
withForwardSlash.substring(1)
else
withForwardSlash
}
def cacheFileToOriginalUrl(fileUrl: String, cacheDir: File): String = {
if (!fileUrl.startsWith(FileUrlPrefix)) return fileUrl
val filePath = fileUrl.stripPrefix(FileUrlPrefix).replaceFirst("^/+", "/")
val filePath = normalizedFilePath(fileUrl)
val cachePaths = Seq(
cacheDir.getAbsolutePath,
cacheDir.getCanonicalPath
).distinct.map(p => if (p.endsWith("/")) p else p + "/")
).distinct.map(p =>
normalizePathForComparison(if (p.endsWith("/") || p.endsWith("\\")) p else p + "/")
)
def extractHttpUrl(relativePath: String): Option[String] = {
val protocolSepIndex = relativePath.indexOf('/')

View File

@ -44,7 +44,11 @@ object DependencyLockManager:
isValid
}
private def artifactUrlForLock(rawUrl: String, cacheDir: Option[File], moduleDesc: String): String =
private def artifactUrlForLock(
rawUrl: String,
cacheDir: Option[File],
moduleDesc: String
): String =
if !rawUrl.startsWith(CacheUrlConversion.FileUrlPrefix) then rawUrl
else
cacheDir match