allow creating root folders too

This commit is contained in:
tibbi 2018-04-16 12:36:37 +02:00
parent cdedabddbb
commit b03db843f2
2 changed files with 14 additions and 4 deletions

View File

@ -66,6 +66,15 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
success(alertDialog)
}
}
else -> {
RootHelpers().createFileFolder(activity, path, false) {
if (it) {
success(alertDialog)
} else {
callback(false)
}
}
}
}
}
@ -91,7 +100,7 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
}
}
else -> {
RootHelpers().createFile(activity, path) {
RootHelpers().createFileFolder(activity, path, true) {
if (it) {
success(alertDialog)
} else {

View File

@ -130,11 +130,12 @@ class RootHelpers {
}
}
fun createFile(activity: SimpleActivity, path: String, callback: (success: Boolean) -> Unit) {
fun createFileFolder(activity: SimpleActivity, path: String, isFile: Boolean, callback: (success: Boolean) -> Unit) {
tryMountAsRW(activity, path) {
val mountPoint = it
val targetPath = path.trim('/')
val cmd = "touch \"/$targetPath\""
val mainCommand = if (isFile) "touch" else "mkdir"
val cmd = "$mainCommand \"/$targetPath\""
val command = object : Command(0, cmd) {
override fun commandCompleted(id: Int, exitcode: Int) {
callback(exitcode == 0)
@ -179,7 +180,7 @@ class RootHelpers {
}
}
if (mountPoint != "" && types != null) {
if (mountPoint.isNotEmpty() && types != null) {
if (types.contains("rw")) {
callback(null)
} else if (types.contains("ro")) {