From ff6bae936d097ce0b022e454f972e2c1e7eb509b Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 30 Sep 2016 10:52:04 +0800 Subject: [PATCH] Fix root shell racing condition --- .../main/java/com/topjohnwu/magisk/utils/Async.java | 2 +- .../main/java/com/topjohnwu/magisk/utils/Utils.java | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java index eed337856..41e4c10d3 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java @@ -46,7 +46,7 @@ public class Async { String busybox = mContext.getApplicationInfo().dataDir + "/lib/libbusybox.so"; String zip = mContext.getApplicationInfo().dataDir + "/lib/libzip.so"; if (Shell.rootAccess()) { - if (!Utils.itemExist(toolPath)) { + if (!Utils.itemExist(false, toolPath)) { Shell.sh( "rm -rf " + toolPath, "mkdir " + toolPath, diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index 2236f572b..4c411aedb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -65,14 +65,16 @@ public class Utils { } public static boolean itemExist(String path) { - List ret; + return itemExist(true, path); + } + + public static boolean itemExist(boolean root, String path) { String command = "if [ -e " + path + " ]; then echo true; else echo false; fi"; - if (Shell.rootAccess()) { - ret = Shell.su(command); + if (Shell.rootAccess() && root) { + return Boolean.parseBoolean(Shell.su(command).get(0)); } else { - ret = Shell.sh(command); + return new File(path).exists(); } - return Boolean.parseBoolean(ret.get(0)); } public static boolean commandExists(String s) {