From 8f336838f55b3deeaea1d01cd1e51a59399c783e Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 16 Apr 2018 19:23:37 +0200 Subject: [PATCH] implement root file/folder deleting --- .../filemanager/helpers/RootHelpers.kt | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/helpers/RootHelpers.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/helpers/RootHelpers.kt index 079057d6..296aef79 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/helpers/RootHelpers.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/helpers/RootHelpers.kt @@ -164,8 +164,8 @@ class RootHelpers(val activity: Activity) { // inspired by Amaze File Manager private fun tryMountAsRW(path: String, callback: (mountPoint: String?) -> Unit) { val mountPoints = ArrayList() - - val command = object : Command(0, "mount") { + val cmd = "mount" + val command = object : Command(0, cmd) { override fun commandOutput(id: Int, line: String) { mountPoints.add(line) super.commandOutput(id, line) @@ -203,8 +203,8 @@ class RootHelpers(val activity: Activity) { runCommand(command) } - private fun mountAsRW(commandString: String, callback: (mountPoint: String) -> Unit) { - val command = object : Command(0, commandString) { + private fun mountAsRW(cmd: String, callback: (mountPoint: String) -> Unit) { + val command = object : Command(0, cmd) { override fun commandOutput(id: Int, line: String) { callback(line) super.commandOutput(id, line) @@ -215,6 +215,19 @@ class RootHelpers(val activity: Activity) { } fun deleteFiles(fileDirItems: ArrayList) { + tryMountAsRW(fileDirItems.first().path) { + fileDirItems.forEach { + val targetPath = it.path.trim('/') + if (targetPath.isEmpty()) { + return@forEach + } + val mainCommand = if (it.isDirectory) "rm -rf" else "rm" + val cmd = "$mainCommand \"/$targetPath\"" + val command = object : Command(0, cmd) {} + + runCommand(command) + } + } } }