diff --git a/designer-base/src/main/java/com/fr/design/update/utils/UpdateFileUtils.java b/designer-base/src/main/java/com/fr/design/update/utils/UpdateFileUtils.java index b2149be8f0..9caaf2d863 100644 --- a/designer-base/src/main/java/com/fr/design/update/utils/UpdateFileUtils.java +++ b/designer-base/src/main/java/com/fr/design/update/utils/UpdateFileUtils.java @@ -27,9 +27,26 @@ public class UpdateFileUtils { List versions = new ArrayList<>(); if (versionBackup != null) { for (File file : versionBackup) { - if (file.isDirectory() && file.length() > 0) { - versions.add(file.getName()); - } else { + boolean canBackup = true; + if (file.isDirectory()) { + File[] libs = file.listFiles(); + if (libs == null || libs.length == 0) { + canBackup = false; + } else { + for (File lib : libs) { + if (lib.isDirectory()) { + File[] jars = lib.listFiles(); + if (jars == null || jars.length == 0) { + canBackup = false; + } + } + } + } + if (canBackup) { + versions.add(file.getName()); + } + } + if (!canBackup) { StableUtils.deleteFile(file); } } diff --git a/designer-base/src/test/java/com/fr/design/update/utils/UpdateFileUtilsTest.java b/designer-base/src/test/java/com/fr/design/update/utils/UpdateFileUtilsTest.java index 0e91e9d684..a188125ed2 100644 --- a/designer-base/src/test/java/com/fr/design/update/utils/UpdateFileUtilsTest.java +++ b/designer-base/src/test/java/com/fr/design/update/utils/UpdateFileUtilsTest.java @@ -15,8 +15,9 @@ public class UpdateFileUtilsTest { @Test public void testListFilteredFiles() { + StableUtils.mkdirs(new File("home/backup/version/lib/jars")); String[] result = UpdateFileUtils.listFilteredFiles("home", "backup"); - Assert.assertEquals(0, result.length); - StableUtils.deleteFile(new File(StableUtils.pathJoin("home"))); + Assert.assertEquals(1, result.length); + StableUtils.deleteFile(new File("home")); } }