[java-identity-provider] branch master updated: IDP-1499 Remove spurious files after an upgrade

Rod Widdowson rdw at steadingsoftware.com
Sat Dec 21 12:01:11 EST 2019


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch master
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=2970c80578fedb4f0c8b2506705c549f15634daf

The following commit(s) were added to refs/heads/master by this push:
       new  2970c80   IDP-1499 Remove spurious files after an upgrade
2970c80 is described below

commit 2970c80578fedb4f0c8b2506705c549f15634daf
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sat Dec 21 16:58:41 2019 +0000

    IDP-1499 Remove spurious files after an upgrade
    
    https://issues.shibboleth.net/jira/browse/IDP-1499
    
    This is data driven, but initially its just credentials/secrets.properties
---
 .../idp/installer/CurrentInstallState.java         | 10 +++++++
 .../net/shibboleth/idp/installer/V4Install.java    | 18 ++++++++++++
 .../installer/impl/CurrentInstallStateImpl.java    | 34 ++++++++++++++++++++++
 3 files changed, 62 insertions(+)

diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/CurrentInstallState.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/CurrentInstallState.java
index 82446b6..a082059 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/CurrentInstallState.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/CurrentInstallState.java
@@ -17,8 +17,11 @@
 
 package net.shibboleth.idp.installer;
 
+import java.nio.file.Path;
+import java.util.List;
 import java.util.Properties;
 
+import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import org.apache.tools.ant.BuildException;
@@ -59,4 +62,11 @@ public interface CurrentInstallState extends InitializableComponent {
      * @return the properties, or null if this is a new install.
      */
     @Nullable Properties getCurrentlyInstalledProperties();
+
+    /** Return the list of paths of files which were not there prior to the install
+     * but which might be created by the installed but to no purpose.
+     * @return the list of paths.
+     * @return
+     */
+    @Nonnull List<Path> getPathsToBeDeleted();
 }
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/V4Install.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/V4Install.java
index fd14e3f..6946610 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/V4Install.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/V4Install.java
@@ -103,6 +103,7 @@ public class V4Install extends AbstractInitializableComponent {
         populatePropertyFiles(keyManager.isCreatedSealer());
         handleEditWebApp();
         populateUserDirectories();
+        deleteSpuriousFiles();
         generateMetadata();
         reprotect();
     }
@@ -377,6 +378,23 @@ public class V4Install extends AbstractInitializableComponent {
         InstallerSupport.createDirectory(targetBase.resolve("logs"));
     }
     
+    /** Delete those files which were created but not needed.
+     * @throws BuildException if badness occurs
+     */
+    protected void deleteSpuriousFiles() throws BuildException {
+        for (final Path p : currentState.getPathsToBeDeleted()) {
+            if (!Files.exists(p)) {
+                log.debug("File to be deleted did exist?");
+            } else {
+                try {
+                    Files.delete(p);
+                } catch (final IOException e) {
+                    log.debug("Delete failed", e);
+                }
+            }
+        }
+    }
+
     /** Create and populate (if it does not exist) the "metadata/idp-metadata.xml" file.
      * @throws BuildException if badness occurs
      */
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CurrentInstallStateImpl.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CurrentInstallStateImpl.java
index eafbece..355ac5a 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CurrentInstallStateImpl.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CurrentInstallStateImpl.java
@@ -23,6 +23,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 import java.util.Properties;
 
 import javax.annotation.Nonnull;
@@ -35,6 +38,7 @@ import net.shibboleth.idp.installer.CurrentInstallState;
 import net.shibboleth.idp.installer.InstallerProperties;
 import net.shibboleth.idp.installer.InstallerSupport;
 import net.shibboleth.idp.spring.IdPPropertiesApplicationContextInitializer;
+import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.utilities.java.support.component.AbstractInitializableComponent;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
@@ -47,6 +51,10 @@ public final class CurrentInstallStateImpl extends AbstractInitializableComponen
 
     /** Where we are installing to. */
     private final Path targetDir;
+    
+    /** The files we will delete if they created on upgrade. */
+    private final String[][] deleteAfterUpgrades = { { "credentials", "secrets.properties", },
+                                                   }; 
 
     /** Whether the IdP properties file exists.*/
     private boolean idpPropertiesPresent;
@@ -62,6 +70,9 @@ public final class CurrentInstallStateImpl extends AbstractInitializableComponen
     
     /** Previous props. */
     private Properties props;
+    
+    /** The files to delete after an upgrade. */
+    @NonnullAfterInit private List<Path> pathsToDelete;
 
     /** Constructor.
      * @param installerProps the installer situation.
@@ -149,6 +160,24 @@ public final class CurrentInstallStateImpl extends AbstractInitializableComponen
         secretsPropertiesPresent = Files.exists(targetDir.resolve("conf").resolve("secrets.properties"));
         findPreviousVersion();
         setupPreviousProps();
+
+        if (null == getInstalledVersion()) {
+            // New install.  We need all files
+            pathsToDelete = Collections.emptyList();
+        } else {
+            pathsToDelete = new ArrayList<>();
+            for (int i = 0; i < deleteAfterUpgrades.length; i++) {
+                Path p = targetDir;
+                final String[] paths = deleteAfterUpgrades[i];
+                for (int j = 0; j < paths.length; j++) {
+                    p = p.resolve(paths[j]);
+                }
+                if (!Files.exists(p)) {
+                    // doesn't exist,  Candidate for deletion
+                    pathsToDelete.add(p);
+                }
+            }
+        }
     }
 
     /** {@inheritDoc} */
@@ -175,4 +204,9 @@ public final class CurrentInstallStateImpl extends AbstractInitializableComponen
     @Nullable public Properties getCurrentlyInstalledProperties() {
         return props;
     }
+
+    /** {@inheritDoc} */
+    public List<Path> getPathsToBeDeleted() {
+        return pathsToDelete;
+    }
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list