[java-identity-provider] 05/05: IDP-1509 V4 Installer: use "attrib /s" on Windows

Rod Widdowson rdw at steadingsoftware.com
Tue Oct 15 10:20:33 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=178785928775436790ae943240dc5280184e2490

commit 178785928775436790ae943240dc5280184e2490
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Oct 15 15:18:46 2019 +0100

    IDP-1509 V4 Installer: use "attrib /s" on Windows
    
        https://issues.shibboleth.net/jira/browse/IDP-1509
        https://issues.shibboleth.net/jira/browse/IDP-1499
---
 .../shibboleth/idp/installer/InstallerSupport.java | 38 +++++++++++++++-------
 .../net/shibboleth/idp/installer/V4Install.java    |  2 ++
 2 files changed, 29 insertions(+), 11 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 e70300c..df0a9f0 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
@@ -25,8 +25,9 @@ import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.taskdefs.Copy;
 import org.apache.tools.ant.taskdefs.Delete;
+import org.apache.tools.ant.taskdefs.Execute;
 import org.apache.tools.ant.taskdefs.Jar;
-import org.apache.tools.ant.taskdefs.optional.windows.Attrib;
+import org.apache.tools.ant.taskdefs.condition.Os;
 import org.apache.tools.ant.types.FileSet;
 import org.apache.tools.ant.types.selectors.PresentSelector;
 import org.apache.tools.ant.types.selectors.PresentSelector.FilePresence;
@@ -89,7 +90,7 @@ public final class InstallerSupport {
     /** Populate a with all the missing files.
      * @param from where to go from
      * @param to where to go to
-     * @throws BuildException if basness occurrs
+     * @throws BuildException if badness occurrs
      * Based on (for instance the following ant<code>
         <!-- flows: copy from dist if not already present -->
         <mkdir dir="${idp.target.dir}/flows" />
@@ -122,16 +123,31 @@ public final class InstallerSupport {
     /** On Windows sets the readOnly attribute recursively.
      * @param directory where
      * @param readOnly what to set it as
+     * @throws BuildException if badness occurrs
      */
-    public static void setReadOnly(final Path directory, final boolean readOnly) {
-        final Attrib attrib = new Attrib();
-        attrib.setReadonly(readOnly);
-        final FileSet where = new FileSet();
-        where.setDir(directory.toFile());
-        where.setIncludes("**/**");
-        attrib.addFileset(where);
-        attrib.setProject(ANT_PROJECT);
-        attrib.execute();
+    public static void setReadOnly(final Path directory, final boolean readOnly) throws BuildException {
+        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 /s +r *";
+        } else { 
+            line = "cmd /c attrib /s -r *";
+        }
+        final String[] command = line.split(" ");
+
+        final Execute exec = new Execute();
+        exec.setCommandline(command);
+        exec.setWorkingDirectory(directory.toFile());
+        exec.setAntRun(ANT_PROJECT);
+        try {
+            exec.execute();
+        } catch (final IOException e) {
+            log.warn("{} failed: ", line, e);
+            throw new BuildException(e);
+        }
     }
 
     /** Delete the tree.
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 5a2d92f..a2767e2 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
@@ -322,6 +322,8 @@ public class V4Install extends AbstractInitializableComponent {
      * @throws BuildException if badness occurs
      */
     protected void reprotect() throws BuildException {
+        InstallerSupport.setReadOnly(installerProps.getTargetDir().resolve("dist"), true);
+        InstallerSupport.setReadOnly(installerProps.getTargetDir().resolve("system"), true);
         log.warn("Reprotect Implementation still pending");
     }
 

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


More information about the commits mailing list