Improve osgi-uninstall
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 23 May 2023 09:43:04 +0000 (11:43 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 23 May 2023 09:43:04 +0000 (11:43 +0200)
src/org/argeo/build/Make.java

index 33291b20ba05289043ba7aab26ede874ba6391a3..70bf8b5c25f16f8bd3fbd2baaa1c95aebfbcb234 100644 (file)
@@ -355,8 +355,7 @@ public class Make {
                                if (Files.exists(targetJarP)) {
                                        Files.delete(targetJarP);
                                        Path targetParent = targetJarP.getParent();
-                                       if (!Files.list(targetParent).iterator().hasNext())
-                                               Files.delete(targetParent);
+                                       deleteEmptyParents(targetA2, targetParent);
                                        logger.log(DEBUG, "Removed " + targetJarP);
                                        count++;
                                }
@@ -371,6 +370,18 @@ public class Make {
                logger.log(INFO, uninstall ? count + " bundles removed" : count + " bundles installed or updated");
        }
 
+       /** Delete empty parent directory up to the A2 target (included). */
+       void deleteEmptyParents(Path targetA2, Path targetParent) throws IOException {
+               if (!Files.isDirectory(targetParent))
+                       throw new IllegalArgumentException(targetParent + " must be a directory");
+               if (!Files.list(targetParent).iterator().hasNext()) {
+                       Files.delete(targetParent);
+                       if (Files.isSameFile(targetA2, targetParent))
+                               return;// stop after deleting A2 base
+                       deleteEmptyParents(targetA2, targetParent.getParent());
+               }
+       }
+
        /** Package a single bundle. */
        void createBundle(String branch, String bundle, String category) throws IOException {
                final Path source;