manager: use busybox for tar and du commands as not all devices has it most likely and if module size is 0 bytes then show null

This commit is contained in:
Rifat Azad
2025-06-24 17:43:18 +06:00
parent 30e2ed5db5
commit 092eb1b23d
2 changed files with 7 additions and 5 deletions

View File

@@ -1089,6 +1089,7 @@ fun ModuleItem(
} }
fun formatSize(size: Long): String { fun formatSize(size: Long): String {
if (size == 0L) return "null"
val kb = 1024 val kb = 1024
val mb = kb * 1024 val mb = kb * 1024
val gb = mb * 1024 val gb = mb * 1024

View File

@@ -28,6 +28,7 @@ import java.io.File
* @date 2023/1/1. * @date 2023/1/1.
*/ */
private const val TAG = "KsuCli" private const val TAG = "KsuCli"
private const val BUSYBOX = "/data/adb/ksu/bin/busybox"
private fun ksuDaemonMagicPath(): String { private fun ksuDaemonMagicPath(): String {
return ksuApp.applicationInfo.nativeLibraryDir + File.separator + "libksud_magic.so" return ksuApp.applicationInfo.nativeLibraryDir + File.separator + "libksud_magic.so"
@@ -490,7 +491,7 @@ fun moduleBackup(): Boolean {
val internalBackupDir = "/sdcard/.ksunext/modules" val internalBackupDir = "/sdcard/.ksunext/modules"
val internalBackupPath = "$internalBackupDir/$tarName" val internalBackupPath = "$internalBackupDir/$tarName"
val tarCmd = "tar -cpf $tarPath -C /data/adb/modules $(ls /data/adb/modules)" val tarCmd = "$BUSYBOX tar -cpf $tarPath -C /data/adb/modules $(ls /data/adb/modules)"
val tarResult = ShellUtils.fastCmd(shell, tarCmd).trim() val tarResult = ShellUtils.fastCmd(shell, tarCmd).trim()
if (tarResult.isNotEmpty()) return false if (tarResult.isNotEmpty()) return false
@@ -511,7 +512,7 @@ fun moduleRestore(): Boolean {
val tarPath = ShellUtils.fastCmd(shell, findTarCmd).trim() val tarPath = ShellUtils.fastCmd(shell, findTarCmd).trim()
if (tarPath.isEmpty()) return false if (tarPath.isEmpty()) return false
val extractCmd = "tar -xpf $tarPath -C /data/adb/modules_update" val extractCmd = "$BUSYBOX tar -xpf $tarPath -C /data/adb/modules_update"
val extractResult = ShellUtils.fastCmd(shell, extractCmd).trim() val extractResult = ShellUtils.fastCmd(shell, extractCmd).trim()
return extractResult.isEmpty() return extractResult.isEmpty()
} }
@@ -533,7 +534,7 @@ fun allowlistBackup(): Boolean {
val internalBackupDir = "/sdcard/.ksunext/allowlist" val internalBackupDir = "/sdcard/.ksunext/allowlist"
val internalBackupPath = "$internalBackupDir/$tarName" val internalBackupPath = "$internalBackupDir/$tarName"
val tarCmd = "tar -cpf $tarPath -C /data/adb/ksu .allowlist" val tarCmd = "$BUSYBOX tar -cpf $tarPath -C /data/adb/ksu .allowlist"
val tarResult = ShellUtils.fastCmd(shell, tarCmd).trim() val tarResult = ShellUtils.fastCmd(shell, tarCmd).trim()
if (tarResult.isNotEmpty()) return false if (tarResult.isNotEmpty()) return false
@@ -556,7 +557,7 @@ fun allowlistRestore(): Boolean {
if (tarPath.isEmpty()) return false if (tarPath.isEmpty()) return false
// Extract the tar to /data/adb/ksu (restores .allowlist folder with permissions) // Extract the tar to /data/adb/ksu (restores .allowlist folder with permissions)
val extractCmd = "tar -xpf $tarPath -C /data/adb/ksu" val extractCmd = "$BUSYBOX tar -xpf $tarPath -C /data/adb/ksu"
val extractResult = ShellUtils.fastCmd(shell, extractCmd).trim() val extractResult = ShellUtils.fastCmd(shell, extractCmd).trim()
return extractResult.isEmpty() return extractResult.isEmpty()
} }
@@ -623,7 +624,7 @@ fun currentMountSystem(): String {
fun getModuleSize(dir: File): Long { fun getModuleSize(dir: File): Long {
val shell = getRootShell() val shell = getRootShell()
val cmd = "du -sb '${dir.absolutePath}' | awk '{print \$1}'" val cmd = "$BUSYBOX du -sb '${dir.absolutePath}' | awk '{print \$1}'"
val result = ShellUtils.fastCmd(shell, cmd).trim() val result = ShellUtils.fastCmd(shell, cmd).trim()
return result.toLongOrNull() ?: 0L return result.toLongOrNull() ?: 0L
} }