Skip to content

Commit

Permalink
Revert "make delete faster, use an NIO file walker"
Browse files Browse the repository at this point in the history
This reverts commit 7dcaf54.
  • Loading branch information
eed3si9n committed Jun 25, 2018
1 parent 55fd2ca commit 57870f2
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions io/src/main/scala/sbt/io/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ import java.io.{
BufferedWriter,
File,
InputStream,
IOException,
OutputStream,
PrintWriter
}
import java.io.{ ObjectInputStream, ObjectStreamClass, FileNotFoundException }
import java.net.{ URI, URISyntaxException, URL }
import java.nio.charset.Charset
import java.nio.file.{FileSystems, Files, Paths, Path, SimpleFileVisitor, FileVisitResult}
import java.nio.file.attribute.{PosixFilePermissions, BasicFileAttributes}
import java.nio.file.FileSystems
import java.nio.file.attribute.PosixFilePermissions
import java.util.Properties
import java.util.jar.{ Attributes, JarEntry, JarOutputStream, Manifest }
import java.util.zip.{ CRC32, ZipEntry, ZipInputStream, ZipOutputStream }
Expand Down Expand Up @@ -455,24 +454,14 @@ object IO {

/** Deletes `file`, recursively if it is a directory. */
def delete(file: File): Unit = {
object deleter extends SimpleFileVisitor[Path] {
override def visitFile(file: Path, attr: BasicFileAttributes): FileVisitResult = {
translate("Error deleting file " + file.toFile + ": "){
Files.delete(file)
}
FileVisitResult.CONTINUE
}

override def postVisitDirectory(dir: Path, e: IOException): FileVisitResult = {
if (e eq null) {
translate("Error deleting file " + dir.toFile + ": ") {
Files.delete(dir)
}
FileVisitResult.CONTINUE
} else throw e // directory iteration failed
translate("Error deleting file " + file + ": ") {
val deleted = file.delete()
if (!deleted && file.isDirectory) {
delete(listFiles(file))
file.delete
()
}
}
Files.walkFileTree(file.toPath, deleter)
}

/** Returns the children of directory `dir` that match `filter` in a non-null array.*/
Expand Down

0 comments on commit 57870f2

Please sign in to comment.