File.deleteRecursively returns true even if path specified by File does not exist.
False is returned only in case of incomplete deletion. Distinguish situations when file was not deleted because it's vanished after listing and because of some other error.
This commit is contained in:
@@ -367,7 +367,7 @@ public fun File.copyRecursively(dst: File,
|
||||
*
|
||||
* @return `true` if the file or directory is successfully deleted, `false` otherwise.
|
||||
*/
|
||||
public fun File.deleteRecursively(): Boolean = walkBottomUp().fold(exists(), { res, it -> it.delete() && res })
|
||||
public fun File.deleteRecursively(): Boolean = walkBottomUp().fold(true, { res, it -> (it.delete() || !it.exists()) && res })
|
||||
|
||||
/**
|
||||
* Returns an array of files and directories in the directory that match the specified [filter]
|
||||
|
||||
@@ -440,7 +440,7 @@ class FilesTest {
|
||||
|
||||
assertTrue(dir.deleteRecursively())
|
||||
assertFalse(dir.exists())
|
||||
assertFalse(dir.deleteRecursively())
|
||||
assertTrue(dir.deleteRecursively())
|
||||
}
|
||||
|
||||
@test fun deleteRecursivelyWithFail() {
|
||||
@@ -449,7 +449,7 @@ class FilesTest {
|
||||
try {
|
||||
if (restricted.setReadable(false)) {
|
||||
if (File(basedir, "7.txt").setReadable(false)) {
|
||||
basedir.deleteRecursively()
|
||||
assertFalse(basedir.deleteRecursively(), "Expected incomplete recursive deletion.")
|
||||
restricted.setReadable(true)
|
||||
File(basedir, "7.txt").setReadable(true)
|
||||
var i = 0
|
||||
|
||||
Reference in New Issue
Block a user