From 20183d448d9bbd6a557e0a535ae89ce514d36488 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 16 Apr 2018 21:42:52 +0200 Subject: [PATCH] properly determine if the given root item is a file or folder --- .../filemanager/helpers/RootHelpers.kt | 45 ++++++++++++++----- 1 file changed, 35 insertions(+), 10 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 296aef79..0946bae2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/helpers/RootHelpers.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/helpers/RootHelpers.kt @@ -32,22 +32,47 @@ class RootHelpers(val activity: Activity) { val hiddenArgument = if (activity.config.shouldShowHidden) "-A " else "" val cmd = "ls $hiddenArgument$path" + getFullLines(path) { + val fullLines = it + + val command = object : Command(0, cmd) { + override fun commandOutput(id: Int, line: String) { + val file = File(path, line) + val fullLine = fullLines.firstOrNull { it.endsWith(" $line") } + val isDirectory = fullLine?.startsWith('d') ?: file.isDirectory + val fileDirItem = FileDirItem(file.absolutePath, line, isDirectory, 0, 0) + files.add(fileDirItem) + super.commandOutput(id, line) + } + + override fun commandCompleted(id: Int, exitcode: Int) { + if (files.isEmpty()) { + callback(path, files) + } else { + getChildrenCount(files, path, callback) + } + + super.commandCompleted(id, exitcode) + } + } + + runCommand(command) + } + } + + private fun getFullLines(path: String, callback: (ArrayList) -> Unit) { + val fullLines = ArrayList() + val hiddenArgument = if (activity.config.shouldShowHidden) "-Al " else "-l " + val cmd = "ls $hiddenArgument$path" + val command = object : Command(0, cmd) { override fun commandOutput(id: Int, line: String) { - val file = File(path, line) - val isDirectory = file.isDirectory - val fileDirItem = FileDirItem(file.absolutePath, line, isDirectory, 0, 0) - files.add(fileDirItem) + fullLines.add(line) super.commandOutput(id, line) } override fun commandCompleted(id: Int, exitcode: Int) { - if (files.isEmpty()) { - callback(path, files) - } else { - getChildrenCount(files, path, callback) - } - + callback(fullLines) super.commandCompleted(id, exitcode) } }