Skip to content

Commit

Permalink
Merge pull request #235 from eatkins/io-bug-fixes
Browse files Browse the repository at this point in the history
Io bug fixes
  • Loading branch information
eed3si9n authored May 2, 2019
2 parents 90dc829 + fa0d0ee commit ade240d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions io/src/main/scala/sbt/io/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -551,17 +551,23 @@ object IO {
deleteEmpty(parents(files.toSet))
}

/** Deletes `file`, recursively if it is a directory. */
/**
* Deletes `file`, recursively if it is a directory. Note that this method may silently fail to
* delete the file (or directory) if any errors occur.
*/
def delete(file: File): Unit = Retry {
try {
FileTreeView.default.list(file.toPath).foreach {
case (dir, attrs) if attrs.isDirectory => delete(dir.toFile)
case (f, _) => Files.deleteIfExists(f)
case (f, _) =>
try Files.deleteIfExists(f)
catch { case _: IOException => }
}
} catch {
case _: NotDirectoryException =>
}
Files.deleteIfExists(file.toPath)
try Files.deleteIfExists(file.toPath)
catch { case _: IOException => }
()
}

Expand Down
1 change: 0 additions & 1 deletion io/src/main/scala/sbt/nio/file/Glob.scala
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,6 @@ private[sbt] object FileGlobApi {
}
def /(component: String): Glob = Glob(file.toPath.resolve(component))
def \(component: String): Glob = this / component
def glob: Glob = Glob(file)
def glob(filter: FileFilter): Glob = filter match {
case AllPassFilter => Glob(absolutePath(file), AnyPath)
case f => Glob(absolutePath(file)) / convert(f)
Expand Down
3 changes: 2 additions & 1 deletion io/src/test/scala/sbt/nio/GlobPathFinderSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.scalatest.FlatSpec
import sbt.io.syntax._
import sbt.io.{ AllPassFilter, IO, NothingFilter, PathFinder }
import sbt.nio.file.{ AnyPath, Glob, RecursiveGlob }
import sbt.nio.file.syntax._

object GlobPathFinderSpec {
implicit class PathFinderOps[P](val p: P)(implicit f: P => PathFinder) {
Expand Down Expand Up @@ -56,7 +57,7 @@ class GlobPathFinderSpec extends FlatSpec {
}
it should "implicitly build a glob" in IO.withTemporaryDirectory { dir =>
// These use the FileBuilder extension class for file.
assert(dir.glob == Glob(dir))
assert(dir.toGlob == Glob(dir))
assert(dir * AllPassFilter == Glob(dir, AnyPath))
assert((dir glob AllPassFilter) == Glob(dir, AnyPath))
assert(dir ** AllPassFilter == Glob(dir, RecursiveGlob))
Expand Down

0 comments on commit ade240d

Please sign in to comment.