Merge pull request #5855 from eatkins/symlinks

Skip contents of symlinked directories in clean
This commit is contained in:
eugene yokota 2020-09-15 16:08:18 -04:00 committed by GitHub
commit 3923d52c18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 9 deletions

View File

@ -41,7 +41,7 @@ private[sbt] object Clean {
.list(Glob(path, AnyPath))
.filterNot { case (p, _) => exclude(p) }
.foreach {
case (dir, attrs) if attrs.isDirectory =>
case (dir, attrs) if attrs.isDirectory && !attrs.isSymbolicLink =>
deleteRecursive(dir)
delete(dir)
case (file, _) => delete(file)
@ -89,15 +89,11 @@ private[sbt] object Clean {
val excludeFilter = cleanFilter(scope).value
val delete = cleanDelete(scope).value
val targetDir = (target in scope).?.value.map(_.toPath)
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
targetDir.filter(_ => full).foreach(deleteContents(_, excludeFilter, view, delete))
(cleanFiles in scope).?.value.getOrElse(Nil).foreach { f =>
deleteContents(f.toPath, excludeFilter, view, delete)
}
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
// and file outputs of a task.

View File

@ -0,0 +1,5 @@
import java.nio.file.Files
TaskKey[Unit]("createSymlinkedDirectory") := {
Files.createSymbolicLink(target.value.toPath / "foo", baseDirectory.value.toPath / "foo")
}

View File

@ -0,0 +1 @@
bar

View File

@ -0,0 +1,9 @@
> createSymlinkedDirectory
$ exists target/foo/bar
$ exists foo/bar
> clean
$ absent target/foo
$ exists foo/bar