Skip to content

fix-#9026 eliminate .. in paths #9027

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

Merged
merged 2 commits into from
May 23, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Names.Name
import StdNames.nme
import util.Spans.Span
import util.{SourceFile, SourcePosition}
import scala.jdk.CollectionConverters._
import collection.mutable
import java.nio.file.Paths

Expand Down Expand Up @@ -594,8 +595,15 @@ object ExtractSemanticDB:

def write(source: SourceFile, occurrences: List[SymbolOccurrence], symbolInfos: List[SymbolInformation])(using Context): Unit =
def absolutePath(path: Path): Path = path.toAbsolutePath.normalize
def commonPrefix[T](z: T)(i1: Iterable[T], i2: Iterable[T])(app: (T, T) => T): T =
(i1 lazyZip i2).takeWhile(p => p(0) == p(1)).map(_(0)).foldLeft(z)(app)
val sourcePath = absolutePath(source.file.jpath)
val sourceRoot = absolutePath(Paths.get(ctx.settings.sourceroot.value))
val sourceRoot =
// Here if `sourceRoot` and `sourcePath` do not share a common prefix then `relPath` will not be normalised,
// containing ../.. etc, which is problematic when appending to `/META-INF/semanticdb/` and will not be accepted
// by Files.createDirectories on JDK 11.
val sourceRoot0 = absolutePath(Paths.get(ctx.settings.sourceroot.value))
commonPrefix(sourcePath.getRoot)(sourcePath.asScala, sourceRoot0.asScala)(_ resolve _)
val semanticdbTarget =
val semanticdbTargetSetting = ctx.settings.semanticdbTarget.value
absolutePath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CommentPicklingTest {
Directory.inTempDirectory { tmp =>
val sourceFiles = sources.zipWithIndex.map {
case (src, id) =>
val path = tmp./(File("Src$id.scala")).toAbsolute
val path = tmp./(File(s"Src$id.scala")).toAbsolute
path.writeAll(src)
path.toString
}
Expand Down