hansva commented on code in PR #9617:
URL: https://github.com/apache/hop/pull/9617#discussion_r4652584506


##########
plugins/misc/marketplace/src/main/java/org/apache/hop/marketplace/install/PluginUninstaller.java:
##########
@@ -49,9 +51,22 @@ public void uninstall(String artifactId) throws HopException 
{
               + "'. Only plugins installed via the marketplace can be 
uninstalled this way.");
     }
 
-    // Delete files deepest-first; leave shared lib/core jars (sticky, may be 
used by others)
+    // Delete files deepest-first; leave shared lib/core jars (sticky, may be 
used by others).
+    // Files of a previous version that an update could not remove yet go too, 
unless another
+    // marketplace artifact has installed the same file since.
+    Set<String> paths = new 
LinkedHashSet<>(PluginInstaller.nullSafe(receipt.getPaths()));
+    if (!PluginInstaller.nullSafe(receipt.getObsoletePaths()).isEmpty()) {
+      Set<String> otherReceiptPaths =
+          PluginInstaller.pathsOfOtherReceipts(hopHome, artifactId, log);
+      for (String obsolete : receipt.getObsoletePaths()) {
+        if (StringUtils.isNotBlank(obsolete)
+            && 
!otherReceiptPaths.contains(PluginInstaller.normalizeRelative(obsolete))) {
+          paths.add(obsolete);

Review Comment:
   (Applies to #9616 as well.) The loop now also deletes the obsolete paths, 
which are exactly the files an earlier update could not delete because they 
were in use. A failed delete still aborts the uninstall (the `throw new 
HopException("Failed to remove " + path, e)` further down). On Windows, with an 
old jar still locked, the current version's files are already gone when this 
throws, and the receipt (still listing them) is never removed, so the plugin is 
half uninstalled. Could a failed delete of an obsolete path be logged and kept 
in the receipt instead of aborting?



##########
plugins/misc/marketplace/src/main/java/org/apache/hop/marketplace/install/PluginInstaller.java:
##########
@@ -295,19 +340,394 @@ public void activateAllPending() throws HopException {
           if (staged.getFileName().toString().startsWith(".")) {
             continue;
           }
+          String artifactId = staged.getFileName().toString();
           List<String> paths = collectRelativePaths(staged);
-          activateStaged(staged.getFileName().toString(), paths);
+          // A receipt problem must not stop the other plugins from activating.
+          InstallReceipt receipt = null;
+          try {
+            receipt = readReceipt(hopHome, artifactId);
+          } catch (HopException e) {
+            log.logError(
+                "Could not read the install receipt of staged plugin "
+                    + artifactId
+                    + "; activating it without updating the receipt",

Review Comment:
   When the receipt can't be read, the plugin is activated but the broken 
receipt stays. After that, install (`satisfiedInstall` / `readReceipt`) and 
uninstall both fail on it, and the previous version's obsolete files are never 
removed. Since this block is being reworked anyway: could it write a fresh 
receipt from the staged paths, or at least move the unreadable one aside?



##########
plugins/misc/marketplace/src/main/java/org/apache/hop/marketplace/install/PluginInstaller.java:
##########
@@ -326,38 +773,98 @@ private void activateStaged(String artifactId, 
List<String> relativePaths) throw
     } catch (IOException e) {
       throw new HopException("Failed to activate staged plugin " + artifactId, 
e);
     }
+    // Shared files an earlier version created or replaced and this one no 
longer ships
+    for (Map.Entry<String, SharedFile> entry : 
nullSafe(earlierInstalls).entrySet()) {
+      if (entry.getValue() != null
+          && entry.getValue().getAction() == SharedFileAction.NOT_SHIPPED
+          && !sharedFiles.containsKey(entry.getKey())) {
+        sharedFiles.put(entry.getKey(), entry.getValue());
+      }
+    }
+    return sharedFiles;
+  }
+
+  /**
+   * Where an install of {@code artifactId:version} backs up the shared file 
it replaces: {@code
+   * <artifactId>/<version installed>/<installId>/<path>} under {@link 
#BACKUP_DIR}.
+   */
+  static String backupPath(String artifactId, String version, String 
installId, String relative) {

Review Comment:
   Minor hardening: `artifactId` and `version` go into the path unchecked (the 
version can come from the receipt JSON or the command line, `MavenCoordinates` 
doesn't validate it). A value with `..` or `/` puts the backup outside 
`BACKUP_DIR`; the same applies to `versionDir` in `newInstallId`. Normalizing 
the resolved path and checking it stays under `BACKUP_DIR` (like the zip-entry 
check in `unzipAllowedEntries`) would close that.



##########
plugins/misc/marketplace/src/main/java/org/apache/hop/marketplace/install/PluginInstaller.java:
##########
@@ -368,7 +875,16 @@ private void activateSharedCoreJar(String artifactId, 
String relative, Path from
               + relative
               + " — leaving existing file. "
               + e.getMessage());
+      if (backup != null) {
+        try {
+          Files.deleteIfExists(backup);
+        } catch (IOException deleteError) {
+          log.logError("Could not remove unused backup " + backup, 
deleteError);

Review Comment:
   Minor: only the backup file is removed here. The 
`plugins/.marketplace/backup/<artifact>/<version>/<installId>/lib/core` folders 
created for it stay behind empty, once for every failed copy. Removing the 
empty parents up to `BACKUP_DIR` would keep that tidy.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to