[java-identity-provider] 02/02: IDP-1499 Windows Installer: strip RO bit before updating version file.

Rod Widdowson rdw at steadingsoftware.com
Fri Oct 25 08:59:18 EDT 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=1d162927d3f5ac9c2e386eef54f5d7d85d92b205

commit 1d162927d3f5ac9c2e386eef54f5d7d85d92b205
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Oct 25 13:58:19 2019 +0100

    IDP-1499  Windows Installer: strip RO bit before updating version file.
    
    https://issues.shibboleth.net/jira/browse/IDP-1499
---
 .../shibboleth/idp/installer/InstallerSupport.java | 69 ++++++++++++++++++----
 .../net/shibboleth/idp/installer/V4Install.java    |  7 ++-
 2 files changed, 61 insertions(+), 15 deletions(-)

diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java
index 6b5e940..6b04a4f 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerSupport.java
@@ -58,7 +58,7 @@ public final class InstallerSupport {
 
     /** Method to create a directory and log same.
      * @param dir what to create
-     * @throws BuildException if bad ness occurs
+     * @throws BuildException if badness occurs
      */
     public static void createDirectory(final Path dir) throws BuildException{
         if (!Files.exists(dir)) {
@@ -124,20 +124,46 @@ public final class InstallerSupport {
 
     }
 
-    /** On Windows sets the readOnly attribute recursively.
-     * @param directory where
+    /** On Windows sets the readOnly attribute on a file.
+     * @param file where
      * @param readOnly what to set it as
-     * @throws BuildException if badness occurrs
+     * @throws BuildException if badness occurs
      */
-    public static void setReadOnly(final Path directory, final boolean readOnly) throws BuildException {
+    private static void setReadOnlyFile(final Path file, final boolean readOnly) throws BuildException {
         if (readOnly) {
-            log.debug("Setting readonly bits on {}", directory);
+            log.debug("Setting readonly bits on file {}", file);
         } else {
-            log.debug("Clearing readonly bits on {}", directory);
+            log.debug("Clearing readonly bits on file {}", file);
         }
-        if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
-            log.debug("Not windows. Not [re]setting readonly bit");
-            return;
+        final String line;
+        if (readOnly) {
+            line = "cmd /c attrib +r \"" + file.toString() + "\"";
+        } else {
+            line = "cmd /c attrib -r \"" + file.toString() + "\"";
+        }
+        final String[] command = line.split(" ");
+
+        final Execute exec = new Execute();
+        exec.setCommandline(command);
+        exec.setAntRun(ANT_PROJECT);
+        try {
+            exec.execute();
+        } catch (final IOException e) {
+            log.warn("{} failed: ", line, e);
+            throw new BuildException(e);
+        }
+    }
+
+    /** On Windows sets the readOnly attribute recursively on a directory.
+     * @param directory where
+     * @param readOnly what to set it as
+     * @throws BuildException if badness occurs
+     */
+    public static void setReadOnlyDir(final Path directory, final boolean readOnly) throws BuildException {
+        if (readOnly) {
+            log.debug("Recursively setting readonly bits on directory {}", directory);
+        } else {
+            log.debug("Recursively clearing readonly bits on directory {}", directory);
         }
         final String line;
         if (readOnly) {
@@ -159,11 +185,28 @@ public final class InstallerSupport {
         }
     }
 
+    /** On Windows sets the readOnly attribute on a file or recursively on a directory.
+     * @param path where
+     * @param readOnly what to set it as
+     * @throws BuildException if badness occurs
+     */
+    public static void setReadOnly(final Path path, final boolean readOnly) throws BuildException {
+        if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
+            log.debug("Not windows. Not [re]setting readonly bit");
+            return;
+        }
+        if (Files.isDirectory(path)) {
+            setReadOnlyDir(path, readOnly);
+        } else {
+            setReadOnlyFile(path, readOnly);
+        }
+    }
+
     /** On Non Windows sets the file mode.
      * @param directory where
      * @param permissions what to set
      * @param includes what to include
-     * @throws BuildException if badness occurrs
+     * @throws BuildException if badness occurs
      */
     public static void setMode(final Path directory, final String permissions, final String includes)
             throws BuildException {
@@ -185,7 +228,7 @@ public final class InstallerSupport {
      * @param directory where
      * @param group what to set
      * @param includes what to include
-     * @throws BuildException if badness occurrs
+     * @throws BuildException if badness occurs
      */
     public static void setGroup(final Path directory, final String group, final String includes)
             throws BuildException {
@@ -207,7 +250,7 @@ public final class InstallerSupport {
 
     /** Delete the tree.
      * @param where where
-     * @throws BuildException if badness occurrs
+     * @throws BuildException if badness occurs
      */
     public static void deleteTree(final Path where) throws BuildException {
         if (!Files.exists(where)) {
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 b753acf..bc99af3 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
@@ -134,11 +134,14 @@ public class V4Install extends AbstractInitializableComponent {
             log.info("Update from version {} to version {}", installedVersion, currentVersion);
         }
         try {
+            final Path versFile = installerProps.getTargetDir().resolve("dist").resolve(InstallerSupport.VERSION_NAME);
+            if (Files.exists(versFile) ) {
+                InstallerSupport.setReadOnly(versFile, false);
+            }
             final Properties vers = new Properties();
             vers.setProperty(InstallerSupport.VERSION_NAME, currentVersion);
             vers.setProperty(InstallerSupport.PREVIOUS_VERSION_NAME, installedVersion==null?"":installedVersion);
-            final OutputStream out = new FileOutputStream(
-                    installerProps.getTargetDir().resolve("dist").resolve(InstallerSupport.VERSION_NAME).toFile());
+            final OutputStream out = new FileOutputStream(versFile.toFile());
             vers.store(out, "Version file written at " + Instant.now());
         } catch (final IOException e) {
             log.error("Couldn't write version file", e);

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


More information about the commits mailing list