Commit ff6bae93 authored by topjohnwu's avatar topjohnwu

Fix root shell racing condition

parent 62523c81
......@@ -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,
......
......@@ -65,14 +65,16 @@ public class Utils {
}
public static boolean itemExist(String path) {
List<String> 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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment