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:
Ilya Gorbunov
2015-12-22 19:13:42 +03:00
parent 5e6489f1a2
commit ea3a2eefe7
2 changed files with 3 additions and 3 deletions
@@ -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]