Allow cleanKeepFiles to contain directories

The directory contents will be kept as will empty directories.
This commit is contained in:
Mark Harrah 2012-12-19 10:17:56 -05:00
parent 6c748d97c5
commit ea3e5c3548
3 changed files with 15 additions and 1 deletions

View File

@ -557,9 +557,11 @@ object Defaults extends BuildCommon
def doClean(clean: Seq[File], preserve: Seq[File]): Unit =
IO.withTemporaryDirectory { temp =>
val mappings = preserve.filter(_.exists).zipWithIndex map { case (f, i) => (f, new File(temp, i.toHexString)) }
val (dirs, files) = preserve.filter(_.exists).flatMap(_.***.get).partition(_.isDirectory)
val mappings = files.zipWithIndex map { case (f, i) => (f, new File(temp, i.toHexString)) }
IO.move(mappings)
IO.delete(clean)
IO.createDirectories(dirs) // recreate empty directories
IO.move(mappings.map(_.swap))
}
def runMainTask(classpath: Initialize[Task[Classpath]], scalaRun: Initialize[Task[ScalaRun]]): Initialize[InputTask[Unit]] =

View File

@ -0,0 +1,6 @@
cleanKeepFiles ++= Seq(
target.value / "keep",
target.value / "keepfile",
target.value / "keepdir"
)

View File

@ -0,0 +1,6 @@
$ touch target/keep/a target/keepdir/ target/deletefile target/deletedir/b target/keepfile
$ exists target/keep/ target/keep/a target/keepdir/ target/deletefile target/deletedir/ target/keepfile
> clean
$ exists target/keep/ target/keep/a target/keepdir/ target/keepfile
$ absent target/delete target/deletedir target/deletefile