From 72c061a2a25f3bd39e942591437e64d226bc82f9 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 22 Dec 2024 01:32:16 -0500 Subject: [PATCH] fix: Fixes glob in scripted **Problem** Absolute path handling regressed. **Solution** Create an absolute glob for expression starting with /. --- .../sbt/internal/scripted/FileCommands.scala | 16 ++++++++++------ sbt-app/src/sbt-test/actions/add-alias/test | 2 ++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/internal/util-scripted/src/main/scala/sbt/internal/scripted/FileCommands.scala b/internal/util-scripted/src/main/scala/sbt/internal/scripted/FileCommands.scala index a2aa32db7..a8bd97544 100644 --- a/internal/util-scripted/src/main/scala/sbt/internal/scripted/FileCommands.scala +++ b/internal/util-scripted/src/main/scala/sbt/internal/scripted/FileCommands.scala @@ -56,6 +56,11 @@ class FileCommands(baseDirectory: File) extends BasicStatementHandler { def fromStrings(paths: List[String]) = paths.map(fromString) def fromString(path: String) = new File(baseDirectory, path) def filterFromStrings(exprs: List[String]): List[PathFilter] = { + def globs(exprs: List[String]): List[PathFilter] = + exprs.map { g => + if (g.startsWith("/")) (Glob(g): PathFilter) + else (Glob(baseDirectory, g): PathFilter) + } def orGlobs = { val exprs1 = exprs .mkString("") @@ -63,19 +68,18 @@ class FileCommands(baseDirectory: File) extends BasicStatementHandler { .filter(_ != OR) .toList .map(_.trim) - val combined = exprs1.map(Glob(baseDirectory, _)) match { + val combined = globs(exprs1) match { case Nil => sys.error("unexpected Nil") - case g :: Nil => (g: PathFilter) + case g :: Nil => g case g :: gs => - gs.foldLeft(g: PathFilter) { - case (acc, g) => - acc || (g: PathFilter) + gs.foldLeft(g) { + case (acc, g) => acc || g } } List(combined) } if (exprs.contains("||")) orGlobs - else exprs.map(Glob(baseDirectory, _): PathFilter) + else globs(exprs) } def touch(paths: List[String]): Unit = IO.touch(fromStrings(paths)) diff --git a/sbt-app/src/sbt-test/actions/add-alias/test b/sbt-app/src/sbt-test/actions/add-alias/test index 0269ab4f8..9a7db3782 100644 --- a/sbt-app/src/sbt-test/actions/add-alias/test +++ b/sbt-app/src/sbt-test/actions/add-alias/test @@ -2,3 +2,5 @@ -> demo-failure > +z > z + +$ absent /tmp/non-existent