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:26:24 -07:00
parent 2178abba01
commit b3320ce1ba
4 changed files with 12 additions and 4 deletions

View File

@ -89,11 +89,14 @@ private[sbt] object Clean {
val excludeFilter = cleanFilter(scope).value
val delete = cleanDelete(scope).value
val targetDir = (target in scope).?.value.map(_.toPath)
val targetFiles = (if (full) targetDir else None).fold(Nil: Seq[Path]) { t =>
view.list(t.toGlob / **).collect { case (p, _) if !excludeFilter(p) => p }
def recursiveFiles(dir: Path): Seq[Path] =
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
.flatMap(_.map(_.toPath)) ++ targetFiles
val allFiles = cleanPaths.view ++ targetFiles
allFiles.sorted.reverseIterator.foreach(delete)
// This is the special portion of the task where we clear out the relevant streams

View File

@ -0,0 +1 @@
cleanFiles += baseDirectory.value / "foo"

View File

@ -0,0 +1 @@
baz

View File

@ -0,0 +1,3 @@
> clean
$ absent foo/bar/baz.txt