Skip to content

Commit

Permalink
fix(core.manager): 修复deleteInstalledPlugin方法调用结果总是返回false
Browse files Browse the repository at this point in the history
note:增加一个删除方法,如果有子目录则先删除子目录下的文件

fix #1140
  • Loading branch information
AntonioShare committed Nov 28, 2023
1 parent a8ca3f2 commit 1ccd610
Showing 1 changed file with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,22 +355,41 @@ public boolean deleteInstalledPlugin(String uuid) {

private boolean deletePart(InstalledPlugin.Part part) {
boolean suc = true;
if (!part.pluginFile.delete()) {
if (!deleteFileOrDirectory(part.pluginFile)) {
suc = false;
}
if (part.oDexDir != null) {
if (!part.oDexDir.delete()) {
suc = false;
}
if (part.oDexDir != null && !deleteFileOrDirectory(part.oDexDir)) {
suc = false;
}
if (part.libraryDir != null) {
if (!part.libraryDir.delete()) {
suc = false;
}
if (part.libraryDir != null && !deleteFileOrDirectory(part.libraryDir)) {
suc = false;
}
return suc;
}

/**
* 删除文件或目录,递归删除
*
* @param fileOrDirectory 文件或目录
* @return 是否删除成功
*/
private boolean deleteFileOrDirectory(File fileOrDirectory) {
if (fileOrDirectory == null || !fileOrDirectory.exists()) {
return true;
}
if (fileOrDirectory.isDirectory()) {
File[] files = fileOrDirectory.listFiles();
if (files != null) {
for (File file : files) {
if (!deleteFileOrDirectory(file)) {
return false;
}
}
}
}
return fileOrDirectory.delete();
}

/**
* 当前插件希望采用的ABI。
* 子类可以override重新决定。
Expand Down

0 comments on commit 1ccd610

Please sign in to comment.