Fix root shell racing condition

This commit is contained in:
topjohnwu 2016-09-30 10:52:04 +08:00
parent 62523c815e
commit ff6bae936d
2 changed files with 8 additions and 6 deletions

View File

@ -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,

View File

@ -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) {