Skip to content

Commit

Permalink
Merge pull request #287 from eed3si9n/bport/285
Browse files Browse the repository at this point in the history
[1.3.x] Correctly exclude base from Path.allSubpaths result
  • Loading branch information
eed3si9n authored Jan 27, 2020
2 parents afb0a4f + a73c336 commit f48f2b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 2 additions & 4 deletions io/src/main/scala/sbt/io/PathMapper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,10 @@ abstract class Mapper {
* Selects descendants of `base` directory matching `filter` and maps them to a path relative to `base`.
* `base` itself is not included.
*/
def selectSubpaths(base: File, filter: FileFilter): Traversable[(File, String)] = {
val path = base.toPath
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
}
}

/**
* return a Seq of mappings which effect is to add a whole directory in the generated package
Expand Down
7 changes: 7 additions & 0 deletions io/src/test/scala/sbt/io/PathMapperSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ class PathMapperSpec extends fixture.FlatSpec with Matchers {
mappings should be(empty)
}

it should "not include the base directory" in { tempDirectory =>
val file = Files.createFile(tempDirectory.resolve("file"))
val paths = Path.allSubpaths(tempDirectory.toFile).toVector.map(_._1.toPath).toSet
assert(paths.contains(file))
assert(!paths.contains(tempDirectory))
}

override protected def withFixture(test: OneArgTest): Outcome = {
val tmpDir = Files.createTempDirectory("path-mappings")
try {
Expand Down

0 comments on commit f48f2b7

Please sign in to comment.