From: Mathieu Baudier Date: Wed, 18 Oct 2023 11:15:45 +0000 (+0200) Subject: Fix trying to delete non temprorary jar during installation X-Git-Tag: v2.3.20~4 X-Git-Url: https://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=commitdiff_plain;h=c692c089327ab02a19dc5dae90bb003cdf75956d Fix trying to delete non temprorary jar during installation --- diff --git a/org.argeo.init/src/org/argeo/init/a2/AbstractProvisioningSource.java b/org.argeo.init/src/org/argeo/init/a2/AbstractProvisioningSource.java index 800635c9e..f946add69 100644 --- a/org.argeo.init/src/org/argeo/init/a2/AbstractProvisioningSource.java +++ b/org.argeo.init/src/org/argeo/init/a2/AbstractProvisioningSource.java @@ -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);