Restore old cleanFiles behavior

I inadvertently changed the semantics of clean so that cleanFiles would
only delete the file if it was a regular file. In older versions of sbt,
if a file in cleanFiles was a directory, it would be recursively
deleted.
This commit is contained in:
Ethan Atkins
2019-08-28 16:41:25 -07:00
parent 2178abba01
commit b3320ce1ba
4 changed files with 12 additions and 4 deletions
+7 -4
View File
@@ -89,11 +89,14 @@ private[sbt] object Clean {
val excludeFilter = cleanFilter(scope).value val excludeFilter = cleanFilter(scope).value
val delete = cleanDelete(scope).value val delete = cleanDelete(scope).value
val targetDir = (target in scope).?.value.map(_.toPath) val targetDir = (target in scope).?.value.map(_.toPath)
val targetFiles = (if (full) targetDir else None).fold(Nil: Seq[Path]) { t => def recursiveFiles(dir: Path): Seq[Path] =
view.list(t.toGlob / **).collect { case (p, _) if !excludeFilter(p) => p } view.list(dir.toGlob / **).collect { case (p, _) if !excludeFilter(p) => p }
val targetFiles = (if (full) targetDir else None).fold(Nil: Seq[Path])(recursiveFiles)
val cleanPaths = (cleanFiles in scope).?.value.getOrElse(Nil).flatMap { f =>
val path = f.toPath
if (Files.isDirectory(path)) path +: recursiveFiles(path) else path :: Nil
} }
val allFiles = (cleanFiles in scope).?.value.toSeq val allFiles = cleanPaths.view ++ targetFiles
.flatMap(_.map(_.toPath)) ++ targetFiles
allFiles.sorted.reverseIterator.foreach(delete) allFiles.sorted.reverseIterator.foreach(delete)
// This is the special portion of the task where we clear out the relevant streams // This is the special portion of the task where we clear out the relevant streams
@@ -0,0 +1 @@
cleanFiles += baseDirectory.value / "foo"
@@ -0,0 +1 @@
baz
@@ -0,0 +1,3 @@
> clean
$ absent foo/bar/baz.txt