Fix trying to delete non temprorary jar during installation
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 18 Oct 2023 11:15:45 +0000 (13:15 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 18 Oct 2023 11:15:45 +0000 (13:15 +0200)
org.argeo.init/src/org/argeo/init/a2/AbstractProvisioningSource.java

index 800635c9e93748214b95c9b286bce88b6be41352..f946add692a062940f0d64f3e2ef44f10e529be5 100644 (file)
@@ -49,16 +49,19 @@ public abstract class AbstractProvisioningSource implements ProvisioningSource {
                        } else {
                                Path locatorPath = (Path) locator;
                                Path pathToUse;
-                               if (locator instanceof Path && Files.isDirectory(locatorPath))
+                               boolean isTemp = false;
+                               if (locator instanceof Path && Files.isDirectory(locatorPath)) {
                                        pathToUse = toTempJar(locatorPath);
-                               else
+                                       isTemp = true;
+                               } else {
                                        pathToUse = locatorPath;
+                               }
                                Bundle bundle;
                                try (InputStream in = newInputStream(pathToUse)) {
                                        bundle = bc.installBundle(locatorPath.toAbsolutePath().toString(), in);
                                }
 
-                               if (pathToUse != null)
+                               if (isTemp && pathToUse != null)
                                        Files.deleteIfExists(pathToUse);
                                return bundle;
                        }
@@ -76,14 +79,20 @@ public abstract class AbstractProvisioningSource implements ProvisioningSource {
                                        bundle.update(in);
                                }
                        } else {
-                               Path tempJar = null;
-                               if (locator instanceof Path && Files.isDirectory((Path) locator))
-                                       tempJar = toTempJar((Path) locator);
-                               try (InputStream in = newInputStream(tempJar != null ? tempJar : locator)) {
+                               Path locatorPath = (Path) locator;
+                               Path pathToUse;
+                               boolean isTemp = false;
+                               if (locator instanceof Path && Files.isDirectory(locatorPath)) {
+                                       pathToUse = toTempJar(locatorPath);
+                                       isTemp = true;
+                               } else {
+                                       pathToUse = locatorPath;
+                               }
+                               try (InputStream in = newInputStream(pathToUse)) {
                                        bundle.update(in);
                                }
-                               if (tempJar != null)
-                                       Files.deleteIfExists(tempJar);
+                               if (isTemp && pathToUse != null)
+                                       Files.deleteIfExists(pathToUse);
                        }
                } catch (BundleException | IOException e) {
                        throw new A2Exception("Cannot update module " + module, e);