Skip to content

Commit 5358651

Browse files
authored
Merge pull request #9027 from dotty-staging/fix-#9026
fix-#9026 eliminate .. in paths
2 parents 59587ba + 565abde commit 5358651

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Names.Name
1212
import StdNames.nme
1313
import util.Spans.Span
1414
import util.{SourceFile, SourcePosition}
15+
import scala.jdk.CollectionConverters._
1516
import collection.mutable
1617
import java.nio.file.Paths
1718

@@ -594,8 +595,15 @@ object ExtractSemanticDB:
594595

595596
def write(source: SourceFile, occurrences: List[SymbolOccurrence], symbolInfos: List[SymbolInformation])(using Context): Unit =
596597
def absolutePath(path: Path): Path = path.toAbsolutePath.normalize
598+
def commonPrefix[T](z: T)(i1: Iterable[T], i2: Iterable[T])(app: (T, T) => T): T =
599+
(i1 lazyZip i2).takeWhile(p => p(0) == p(1)).map(_(0)).foldLeft(z)(app)
597600
val sourcePath = absolutePath(source.file.jpath)
598-
val sourceRoot = absolutePath(Paths.get(ctx.settings.sourceroot.value))
601+
val sourceRoot =
602+
// Here if `sourceRoot` and `sourcePath` do not share a common prefix then `relPath` will not be normalised,
603+
// containing ../.. etc, which is problematic when appending to `/META-INF/semanticdb/` and will not be accepted
604+
// by Files.createDirectories on JDK 11.
605+
val sourceRoot0 = absolutePath(Paths.get(ctx.settings.sourceroot.value))
606+
commonPrefix(sourcePath.getRoot)(sourcePath.asScala, sourceRoot0.asScala)(_ resolve _)
599607
val semanticdbTarget =
600608
val semanticdbTargetSetting = ctx.settings.semanticdbTarget.value
601609
absolutePath(

compiler/test/dotty/tools/dotc/core/tasty/CommentPicklingTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class CommentPicklingTest {
8282
Directory.inTempDirectory { tmp =>
8383
val sourceFiles = sources.zipWithIndex.map {
8484
case (src, id) =>
85-
val path = tmp./(File("Src$id.scala")).toAbsolute
85+
val path = tmp./(File(s"Src$id.scala")).toAbsolute
8686
path.writeAll(src)
8787
path.toString
8888
}

0 commit comments

Comments
 (0)