From 4035e01a265d2747ec74404bd0a4d9c4c5f58715 Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Tue, 16 Jul 2019 11:36:10 -0700 Subject: [PATCH] Fix bug in converting OrFilter This was reported in https://github.com/sbt/sbt/issues/4868. There were multiple copy paste errors. --- io/src/main/scala/sbt/internal/nio/Globs.scala | 2 +- io/src/main/scala/sbt/nio/file/Glob.scala | 2 +- io/src/test/scala/sbt/internal/nio/GlobsSpec.scala | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/io/src/main/scala/sbt/internal/nio/Globs.scala b/io/src/main/scala/sbt/internal/nio/Globs.scala index 9faa5792..3f8bf7f1 100644 --- a/io/src/main/scala/sbt/internal/nio/Globs.scala +++ b/io/src/main/scala/sbt/internal/nio/Globs.scala @@ -62,7 +62,7 @@ private[sbt] object Globs { case (left, Some(NoPath)) => left case (any @ Some(AnyPath), _) => any case (_, any @ Some(AnyPath)) => any - case (Some(left: Matcher), Some(right: Matcher)) => Some(Matcher.and(left, right)) + case (Some(left: Matcher), Some(right: Matcher)) => Some(Matcher.or(left, right)) case _ => None } } diff --git a/io/src/main/scala/sbt/nio/file/Glob.scala b/io/src/main/scala/sbt/nio/file/Glob.scala index 09ae830c..55f5175a 100644 --- a/io/src/main/scala/sbt/nio/file/Glob.scala +++ b/io/src/main/scala/sbt/nio/file/Glob.scala @@ -492,7 +492,7 @@ object RelativeGlob { * @return true it the path matches. */ override def matches(path: Path): Boolean = left.matches(path) || right.matches(path) - override def toString: String = s"($left && $right)" + override def toString: String = s"($left || $right)" } private[file] final case class AndMatcher(left: Matcher, right: Matcher) extends Matcher { override private[sbt] def matchers: List[Matcher] = this :: Nil diff --git a/io/src/test/scala/sbt/internal/nio/GlobsSpec.scala b/io/src/test/scala/sbt/internal/nio/GlobsSpec.scala index a3e26897..b6b5bc3c 100644 --- a/io/src/test/scala/sbt/internal/nio/GlobsSpec.scala +++ b/io/src/test/scala/sbt/internal/nio/GlobsSpec.scala @@ -139,4 +139,12 @@ class GlobsSpec extends FlatSpec { assert(!glob.matches(basePath.resolve("foo").resolve("bar.scala"))) assert(glob.matches(basePath.resolve("foo").resolve("baz.java"))) } + it should "apply or with name filters" in { + val excludeFilter: FileFilter = ("Baz.scala": NameFilter) || "Bar.scala" + val includeFilter: NameFilter = "*.scala" + val filter = includeFilter -- excludeFilter + val glob = Globs(basePath, recursive = true, filter) + assert(glob.matches(basePath.resolve("foo").resolve("Foo.scala"))) + assert(!glob.matches(basePath.resolve("foo").resolve("Bar.scala"))) + } }