Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions os/src/FileOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,16 @@ object copy {
* any files or folders in the target path, or
* does nothing if there aren't any
*/
object remove extends Function1[Path, Unit]{
def apply(target: Path): Unit = Files.delete(target.wrapped)
object remove extends Function1[Path, Boolean]{
def apply(target: Path): Boolean = apply(target, false)
def apply(target: Path, checkExists: Boolean = false): Boolean = {
if (checkExists) {
Files.delete(target.wrapped)
true
}else{
Files.deleteIfExists(target.wrapped)
}
}

object all extends Function1[Path, Unit]{
def apply(target: Path) = {
Expand All @@ -290,7 +298,7 @@ object remove extends Function1[Path, Unit]{
val nioTarget = target.wrapped
if (Files.exists(nioTarget, LinkOption.NOFOLLOW_LINKS)) {
if (Files.isDirectory(nioTarget, LinkOption.NOFOLLOW_LINKS)) {
walk.stream(target, preOrder = false).foreach(remove)
walk.stream(target, preOrder = false).foreach(remove(_))
}
Files.delete(nioTarget)
}
Expand Down
5 changes: 4 additions & 1 deletion os/test/src/OpTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ object OpTests extends TestSuite{
test("rm"){
// shouldn't crash
os.remove.all(os.pwd/"out"/"scratch"/"nonexistent")
// shouldn't crash
os.remove(os.pwd/"out"/"scratch"/"nonexistent") ==> false

// should crash
intercept[NoSuchFileException]{
os.remove(os.pwd/"out"/"scratch"/"nonexistent")
os.remove(os.pwd/"out"/"scratch"/"nonexistent", checkExists = true)
}
}
}
Expand Down