From 301367d8caa95d6400907cac213ebc3d2c2209ba Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Mon, 25 Jun 2018 13:41:02 -0400 Subject: [PATCH 1/3] Revert "Better exception messages, refactoring" This reverts commit 3b00df3478d9b3cb756a6abb476e0055986756b0. --- io/src/main/scala/sbt/io/IO.scala | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/io/src/main/scala/sbt/io/IO.scala b/io/src/main/scala/sbt/io/IO.scala index 416cd271..12dbe4e7 100644 --- a/io/src/main/scala/sbt/io/IO.scala +++ b/io/src/main/scala/sbt/io/IO.scala @@ -463,34 +463,34 @@ object IO { /** Deletes `file`, recursively if it is a directory. */ def delete(file: File): Unit = { object deleter extends SimpleFileVisitor[NioPath] { - def deletePath(path: NioPath) = - translate("Error deleting " + path.toFile + ": ") { + override def visitFile(file: NioPath, attr: BasicFileAttributes): FileVisitResult = { + translate("Error deleting file " + file.toFile + ": ") { try { - Files.delete(path) + Files.delete(file) } catch { - case _: NoSuchFileException => // ignore missing files + case e: NoSuchFileException => } } - - override def visitFile(filePath: NioPath, attr: BasicFileAttributes): FileVisitResult = { - deletePath(filePath) FileVisitResult.CONTINUE } - override def postVisitDirectory(dirPath: NioPath, e: IOException): FileVisitResult = { + override def postVisitDirectory(dir: NioPath, e: IOException): FileVisitResult = { if (e eq null) { - deletePath(dirPath) + translate("Error deleting file " + dir.toFile + ": ") { + try { + Files.delete(dir) + } catch { + case e: NoSuchFileException => + } + } FileVisitResult.CONTINUE } else throw e // directory iteration failed } } - translate("Error during a recursive delete of path " + file + ": ") { - try { - Files.walkFileTree(file.toPath, deleter) - () - } catch { - case _: NoSuchFileException => // ignore missing file or dir - } + try { + Files.walkFileTree(file.toPath, deleter) + } catch { + case e: NoSuchFileException => } } From 55fd2cabe988d629849745f680ef5d770b1c5789 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Mon, 25 Jun 2018 13:41:44 -0400 Subject: [PATCH 2/3] Revert "A few changes to the new delete() code" This reverts commit 293f8ae34137c4c8c28ea19c385ea0ae051675b7. --- io/src/main/scala/sbt/io/IO.scala | 37 ++++++++----------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/io/src/main/scala/sbt/io/IO.scala b/io/src/main/scala/sbt/io/IO.scala index 12dbe4e7..e512f9c9 100644 --- a/io/src/main/scala/sbt/io/IO.scala +++ b/io/src/main/scala/sbt/io/IO.scala @@ -19,15 +19,8 @@ import java.io.{ import java.io.{ ObjectInputStream, ObjectStreamClass, FileNotFoundException } import java.net.{ URI, URISyntaxException, URL } import java.nio.charset.Charset -import java.nio.file.{ - FileSystems, - Files, - Path => NioPath, - SimpleFileVisitor, - FileVisitResult, - NoSuchFileException -} -import java.nio.file.attribute.{ PosixFilePermissions, BasicFileAttributes } +import java.nio.file.{FileSystems, Files, Paths, Path, SimpleFileVisitor, FileVisitResult} +import java.nio.file.attribute.{PosixFilePermissions, BasicFileAttributes} import java.util.Properties import java.util.jar.{ Attributes, JarEntry, JarOutputStream, Manifest } import java.util.zip.{ CRC32, ZipEntry, ZipInputStream, ZipOutputStream } @@ -462,36 +455,24 @@ object IO { /** Deletes `file`, recursively if it is a directory. */ def delete(file: File): Unit = { - object deleter extends SimpleFileVisitor[NioPath] { - override def visitFile(file: NioPath, attr: BasicFileAttributes): FileVisitResult = { - translate("Error deleting file " + file.toFile + ": ") { - try { - Files.delete(file) - } catch { - case e: NoSuchFileException => - } + 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: NioPath, e: IOException): FileVisitResult = { + override def postVisitDirectory(dir: Path, e: IOException): FileVisitResult = { if (e eq null) { translate("Error deleting file " + dir.toFile + ": ") { - try { - Files.delete(dir) - } catch { - case e: NoSuchFileException => - } + Files.delete(dir) } FileVisitResult.CONTINUE } else throw e // directory iteration failed } } - try { - Files.walkFileTree(file.toPath, deleter) - } catch { - case e: NoSuchFileException => - } + Files.walkFileTree(file.toPath, deleter) } /** Returns the children of directory `dir` that match `filter` in a non-null array.*/ From 57870f2e8c4ce05e17cb2c6feb1d70cc98593a8a Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Mon, 25 Jun 2018 13:42:00 -0400 Subject: [PATCH 3/3] Revert "make delete faster, use an NIO file walker" This reverts commit 7dcaf540fcdc7903c0c89679874b6269c61b522e. --- io/src/main/scala/sbt/io/IO.scala | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/io/src/main/scala/sbt/io/IO.scala b/io/src/main/scala/sbt/io/IO.scala index e512f9c9..176a34d2 100644 --- a/io/src/main/scala/sbt/io/IO.scala +++ b/io/src/main/scala/sbt/io/IO.scala @@ -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 } @@ -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.*/