Skip to content

Commit

Permalink
Move post-deletion-failure exist check into the FileOpsHost to save a…
Browse files Browse the repository at this point in the history
…nother IPC transaction
  • Loading branch information
d4rken committed Nov 28, 2024
1 parent 2998605 commit aa8edec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -798,33 +798,16 @@ class LocalGateway @Inject constructor(
log(TAG, VERBOSE) { "delete($mode->ROOT): $path" }
rootOps {
if (Bugs.isDryRun) log(TAG, INFO) { "DRYRUN: Not deleting (root) $javaFile" }
var success = it.delete(path, recursive = true, dryRun = Bugs.isDryRun)

if (!success) {
// TODO We could move this into the root service for better performance?
success = !it.exists(path)
if (success) log(TAG, WARN) { "Tried to delete file, but it's already gone: $path" }
}

if (!success) {
throw IOException("Root delete() call returned false")
}
val success = it.delete(path, recursive = true, dryRun = Bugs.isDryRun)
if (!success) throw IOException("Root delete() call returned false")
}
}

hasShizuku() && (mode == Mode.ADB || mode == Mode.AUTO) -> {
log(TAG, VERBOSE) { "delete($mode->ADB): $path" }
adbOps {
if (Bugs.isDryRun) log(TAG, INFO) { "DRYRUN: Not deleting (adb) $javaFile" }
var success = it.delete(path, recursive = true, dryRun = Bugs.isDryRun)


if (!success) {
// TODO We could move this into the ADB service for better performance?
success = !it.exists(path)
if (success) log(TAG, WARN) { "Tried to delete file, but it's already gone: $path" }
}

val success = it.delete(path, recursive = true, dryRun = Bugs.isDryRun)
if (!success) throw IOException("ADB delete() call returned false")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,20 @@ class FileOpsHost @Inject constructor(

override fun delete(path: LocalPath, recursive: Boolean, dryRun: Boolean): Boolean = try {
log(TAG, VERBOSE) { "delete($path,recursive=$recursive,dryRun=$dryRun)..." }
path.asFile().run {
when {
dryRun -> canWrite()
recursive -> deleteRecursively()
else -> delete()
}
val javaFile = path.asFile()

var success = when {
dryRun -> javaFile.canWrite()
recursive -> javaFile.deleteRecursively()
else -> javaFile.delete()
}

if (!success) {
success = !javaFile.exists()
if (success) log(TAG, WARN) { "Tried to delete file, but it's already gone: $path" }
}

success
} catch (e: Exception) {
log(TAG, ERROR) { "delete(path=$path,recursive=$recursive,dryRun=$dryRun) failed\n${e.asLog()}" }
throw e.wrapToPropagate()
Expand Down

0 comments on commit aa8edec

Please sign in to comment.