From 1ccd6105422435a7ffab0d75565a3ca7d9287a26 Mon Sep 17 00:00:00 2001 From: Antonio Date: Tue, 28 Nov 2023 11:25:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(core.manager):=20=E4=BF=AE=E5=A4=8DdeleteIn?= =?UTF-8?q?stalledPlugin=E6=96=B9=E6=B3=95=E8=B0=83=E7=94=A8=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E6=80=BB=E6=98=AF=E8=BF=94=E5=9B=9Efalse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit note:增加一个删除方法,如果有子目录则先删除子目录下的文件 fix #1140 --- .../core/manager/BasePluginManager.java | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/projects/sdk/core/manager/src/main/java/com/tencent/shadow/core/manager/BasePluginManager.java b/projects/sdk/core/manager/src/main/java/com/tencent/shadow/core/manager/BasePluginManager.java index ccbb0ade9..9d37d7b5e 100644 --- a/projects/sdk/core/manager/src/main/java/com/tencent/shadow/core/manager/BasePluginManager.java +++ b/projects/sdk/core/manager/src/main/java/com/tencent/shadow/core/manager/BasePluginManager.java @@ -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重新决定。