Skip to content

Commit

Permalink
Merge pull request #266 from eatkins/fix-stack-overflow
Browse files Browse the repository at this point in the history
Fix stack overflow in Glob ordering
  • Loading branch information
eed3si9n authored Aug 21, 2019
2 parents 1120b40 + f8dae12 commit 8742353
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions io/src/main/scala/sbt/nio/file/Glob.scala
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,13 @@ object Glob {
case Root(leftRoot) =>
right match {
case Root(rightRoot) => leftRoot.compareTo(rightRoot)
case _: FullFileGlob => -1
case _ => -compare(right, left)
}
case FullFileGlob(leftBase, _, _) =>
right match {
case FullFileGlob(rightBase, _, _) => leftBase.compareTo(rightBase)
case _: Root => 1
case _ => -compare(right, left)
}
}
Expand Down
5 changes: 5 additions & 0 deletions io/src/test/scala/sbt/nio/GlobOrderingSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ class GlobOrderingSpec extends FlatSpec {
val nonRecursive = Glob(dir)
assert(Seq(nonRecursive, recursive).sorted == Seq(recursive, nonRecursive))
}
they should "not stack overflow" in IO.withTemporaryDirectory { dir =>
val exact = Glob(dir.toPath.resolve("foo"))
val fullFile = sbt.internal.nio.Globs(dir.toPath, true, sbt.io.HiddenFileFilter)
assert(Seq(exact, fullFile).sorted == Seq(exact, fullFile))
}
}

0 comments on commit 8742353

Please sign in to comment.