Co-authored-by: vvb2060 <vvb2060@gmail.com>
This commit is contained in:
LoveSy 2021-08-26 19:22:25 +08:00 committed by GitHub
parent 55fe34095d
commit d57617656f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 22 deletions

View File

@ -50,29 +50,32 @@ class ConfigFileManager {
}
}
static void deleteFolderIfExists(Path target) throws IOException {
if (!Files.exists(target)) return;
Files.walkFileTree(target, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException e)
throws IOException {
if (e == null) {
Files.delete(dir);
return FileVisitResult.CONTINUE;
} else {
throw e;
}
}
});
}
private static void moveFolderIfExists(Path source, Path target) throws IOException {
if (!Files.exists(source)) return;
if (Files.exists(target)) {
Files.walkFileTree(target, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException e)
throws IOException {
if (e == null) {
Files.delete(dir);
return FileVisitResult.CONTINUE;
} else {
throw e;
}
}
});
}
deleteFolderIfExists(target);
Files.move(source, target);
}

View File

@ -736,6 +736,13 @@ public class ConfigManager {
db.setTransactionSuccessful();
db.endTransaction();
}
try {
for (var user : UserService.getUsers()) {
removeModulePrefs(user.id, packageName);
}
} catch (Throwable e) {
Log.w(TAG, "remove module prefs for " + packageName);
}
return true;
}
@ -749,7 +756,13 @@ public class ConfigManager {
db.setTransactionSuccessful();
db.endTransaction();
}
return true;
try {
removeModulePrefs(module.userId, module.packageName);
return true;
} catch (IOException e) {
Log.w(TAG, "removeModulePrefs", e);
return false;
}
}
public boolean disableModule(String packageName) {
@ -924,6 +937,12 @@ public class ConfigManager {
}
}
private void removeModulePrefs(int uid, String packageName) throws IOException {
if (packageName == null) return;
var path = Paths.get(getPrefsPath(packageName, uid));
ConfigFileManager.deleteFolderIfExists(path);
}
public String getManagerPackageName() {
return manager;
}