Correctly exclude base from Path.allSubpaths result#285
Merged
dwijnand merged 1 commit intosbt:developfrom Jan 22, 2020
eatkins:scalac-fix
Merged
Correctly exclude base from Path.allSubpaths result#285dwijnand merged 1 commit intosbt:developfrom eatkins:scalac-fix
dwijnand merged 1 commit intosbt:developfrom
eatkins:scalac-fix
Conversation
It was reported in scala/scala#8525 that sbt does not correctly exclude the base directory when calling Path.allSubpaths. This ended up causing jar files to be created with an empty entry. The problem was in an incorrect equality check because the compiler did not flag for us that `PathFinder(base).globRecursive(filter).get()` returned `Seq[File]` but that we were filtering the results by comparing a `File` to a `Path`.
eed3si9n
reviewed
Jan 22, 2020
| def selectSubpaths(base: File, filter: FileFilter): Traversable[(File, String)] = | ||
| PathFinder(base).globRecursive(filter).get().collect { | ||
| case f if f != path => f -> path.relativize(f.toPath).toString | ||
| case f if f != base => f -> base.toPath.relativize(f.toPath).toString |
Member
There was a problem hiding this comment.
I wonder if there could have been some sort of linting that could've caught this.
Contributor
Author
There was a problem hiding this comment.
Yeah. I'm sort of surprised that I didn't get an unrelated type warning. From what I can tell, this seems baked into scala2: scala/scala3#1247. I wonder if there is a compiler plugin though that can catch this kind of thing.
There was a problem hiding this comment.
It does feel like help should be nearby.
val f = new java.io.File("f"); val p = f.toPath; f match { case `p` => }
By coincidence, I just tweaked a similar expression albeit different file and path. I tend to stick to nio.file.Path now. There is a gotcha in that p.endsWith("f") is not String::endsWith.
eed3si9n
approved these changes
Jan 22, 2020
Member
|
No backport candidate flag? |
Member
|
Created the label. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It was reported in scala/scala#8525 that sbt
does not correctly exclude the base directory when calling
Path.allSubpaths. This ended up causing jar files to be created with an
empty entry. The problem was in an incorrect equality check because the
compiler did not flag for us that
PathFinder(base).globRecursive(filter).get()returnedSeq[File]butthat we were filtering the results by comparing a
Fileto aPath.