ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r807464 - in /ant/sandbox/antlibs/compress/trunk/src: main/org/apache/ant/compress/taskdefs/ArchiveBase.java tests/antunit/ar-test.xml tests/antunit/cpio-test.xml tests/antunit/tar-test.xml tests/antunit/zip-test.xml
Date Tue, 25 Aug 2009 03:30:19 GMT
Author: bodewig
Date: Tue Aug 25 03:30:17 2009
New Revision: 807464

URL: http://svn.apache.org/viewvc?rev=807464&view=rev
Log:
port preserve0permissions from core <zip>

Modified:
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/ar-test.xml
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/cpio-test.xml
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tar-test.xml
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-test.xml

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java?rev=807464&r1=807463&r2=807464&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
Tue Aug 25 03:30:17 2009
@@ -59,6 +59,7 @@
 import org.apache.tools.ant.types.resources.ArchiveResource;
 import org.apache.tools.ant.types.resources.FileResource;
 import org.apache.tools.ant.util.FileUtils;
+import org.apache.tools.zip.UnixStat;
 
 /**
  * Base implementation of tasks creating archives.
@@ -72,6 +73,7 @@
     private Mode mode = new Mode();
     private String encoding;
     private boolean filesOnly = true;
+    private boolean preserve0permissions = false;
 
     protected ArchiveBase(StreamFactory factory, EntryBuilder builder) {
         this.factory = factory;
@@ -124,6 +126,15 @@
         filesOnly = b;
     }
 
+    /**
+     * Whether 0 permissions read from an archive should be considered
+     * real permissions (that should be preserved) or missing
+     * permissions (which is the default).
+     */
+    public void setPreserve0permissions(boolean b) {
+        preserve0permissions = b;
+    }
+
     public void execute() {
         validate();
         if (!dest.isExists()) {
@@ -428,7 +439,7 @@
     /**
      * Ensures a forward slash is used as file separator.
      */
-    protected static String bendSlashesForward(String s) {
+    protected String bendSlashesForward(String s) {
         if (s != null) {
             s = s.replace('\\', '/');
             if (File.separatorChar != '/' && File.separatorChar != '\\') { 
@@ -472,8 +483,9 @@
      * Various flags a (archive) resource may hold in addition to
      * being a plain resource.
      */
-    public static class ResourceFlags {
+    public class ResourceFlags {
         private final int mode;
+        private final boolean modeSet;
         private final int gid;
         private final int uid;
         private final ZipExtraField[] extraFields;
@@ -511,9 +523,11 @@
             this.uid = uid;
             this.userName = userName;
             this.groupName = groupName;
+            int m = mode & UnixStat.PERM_MASK;
+            modeSet = mode >= 0 && (m > 0 || (m == 0 && preserve0permissions));
         }
 
-        public boolean hasModeBeenSet() { return mode >= 0; }
+        public boolean hasModeBeenSet() { return modeSet; }
         public int getMode() { return mode; }
 
         public ZipExtraField[] getZipExtraFields() { return extraFields; }
@@ -538,7 +552,7 @@
     /**
      * Various flags a (archive) resource collection may hold.
      */
-    public static class ResourceCollectionFlags extends ResourceFlags {
+    public class ResourceCollectionFlags extends ResourceFlags {
         private final String prefix, fullpath;
         private final int dirMode;
 
@@ -589,7 +603,7 @@
     /**
      * Binds a resource to additional data that may be present.
      */
-    public static class ResourceWithFlags {
+    public class ResourceWithFlags {
         private final Resource r;
         private final ResourceCollectionFlags rcFlags;
         private final ResourceFlags rFlags;

Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/ar-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/ar-test.xml?rev=807464&r1=807463&r2=807464&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/ar-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/ar-test.xml Tue Aug 25 03:30:17 2009
@@ -261,4 +261,32 @@
     </assertResourceDoesntExist>
   </target>
 
+  <target name="-setUp0Permissions" depends="setUp">
+    <property name="src" location="${input}/src.ar"/>
+    <cmp:ar destfile="${src}" preserve0permissions="true">
+      <cmp:arfileset src="../resources/asf-logo.gif.ar"
+                     filemode="0"
+                     includes="asf-logo.gif"/>
+    </cmp:ar>
+  </target>
+
+  <target name="test0PermissionsGetReplaced"
+                     depends="-setUp0Permissions">
+    <cmp:ar destfile="${dest}">
+      <cmp:arfileset src="${src}"
+                     includes="asf-logo.gif"/>
+    </cmp:ar>
+    <checkProperties dateTime="2009-07-31-20:11:13 +0200" mode="644"
+                     uid="1000" gid="1000"/>
+  </target>
+
+  <target name="testPreserve0Permissions"
+                     depends="-setUp0Permissions">
+    <cmp:ar destfile="${dest}" preserve0permissions="true">
+      <cmp:arfileset src="${src}"
+                     includes="asf-logo.gif"/>
+    </cmp:ar>
+    <checkProperties dateTime="2009-07-31-20:11:13 +0200" mode="0"
+                     uid="1000" gid="1000"/>
+  </target>
 </project>

Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/cpio-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/cpio-test.xml?rev=807464&r1=807463&r2=807464&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/cpio-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/cpio-test.xml Tue Aug 25 03:30:17
2009
@@ -293,4 +293,32 @@
     </assertResourceDoesntExist>
   </target>
 
+  <target name="-setUp0Permissions" depends="setUp">
+    <property name="src" location="${input}/src.ar"/>
+    <cmp:ar destfile="${src}" preserve0permissions="true">
+      <cmp:arfileset src="../resources/asf-logo.gif.ar"
+                     filemode="0"
+                     includes="asf-logo.gif"/>
+    </cmp:ar>
+  </target>
+
+  <target name="test0PermissionsGetReplaced"
+                     depends="-setUp0Permissions">
+    <cmp:cpio destfile="${dest}">
+      <cmp:arfileset src="${src}"
+                     includes="asf-logo.gif"/>
+    </cmp:cpio>
+    <checkProperties dateTime="2009-07-31-20:11:13 +0200" mode="644"
+                     uid="1000" gid="1000"/>
+  </target>
+
+  <target name="testPreserve0Permissions"
+                     depends="-setUp0Permissions">
+    <cmp:cpio destfile="${dest}" preserve0permissions="true">
+      <cmp:arfileset src="${src}"
+                     includes="asf-logo.gif"/>
+    </cmp:cpio>
+    <checkProperties dateTime="2009-07-31-20:11:13 +0200" mode="0"
+                     uid="1000" gid="1000"/>
+  </target>
 </project>

Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tar-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tar-test.xml?rev=807464&r1=807463&r2=807464&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tar-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tar-test.xml Tue Aug 25 03:30:17
2009
@@ -309,4 +309,32 @@
     </assertResourceDoesntExist>
   </target>
 
+  <target name="-setUp0Permissions" depends="setUp">
+    <property name="src" location="${input}/src.ar"/>
+    <cmp:ar destfile="${src}" preserve0permissions="true">
+      <cmp:arfileset src="../resources/asf-logo.gif.ar"
+                     filemode="0"
+                     includes="asf-logo.gif"/>
+    </cmp:ar>
+  </target>
+
+  <target name="test0PermissionsGetReplaced"
+                     depends="-setUp0Permissions">
+    <cmp:tar destfile="${dest}">
+      <cmp:arfileset src="${src}"
+                     includes="asf-logo.gif"/>
+    </cmp:tar>
+    <checkProperties dateTime="2009-07-31-20:11:13 +0200" mode="644"
+                     uid="1000" gid="1000"/>
+  </target>
+
+  <target name="testPreserve0Permissions"
+                     depends="-setUp0Permissions">
+    <cmp:tar destfile="${dest}" preserve0permissions="true">
+      <cmp:arfileset src="${src}"
+                     includes="asf-logo.gif"/>
+    </cmp:tar>
+    <checkProperties dateTime="2009-07-31-20:11:13 +0200" mode="0"
+                     uid="1000" gid="1000"/>
+  </target>
 </project>

Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-test.xml?rev=807464&r1=807463&r2=807464&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-test.xml Tue Aug 25 03:30:17
2009
@@ -276,4 +276,37 @@
     </assertResourceDoesntExist>
   </target>
 
+  <target name="-setUp0Permissions" depends="setUp">
+    <property name="src" location="${input}/src.ar"/>
+    <cmp:ar destfile="${src}" preserve0permissions="true">
+      <cmp:arfileset src="../resources/asf-logo.gif.ar"
+                     filemode="0"
+                     includes="asf-logo.gif"/>
+    </cmp:ar>
+    <au:assertTrue>
+      <cmp:hasmode mode="0">
+        <cmp:arentry name="asf-logo.gif">
+          <file file="${src}"/>
+        </cmp:arentry>
+      </cmp:hasmode>
+    </au:assertTrue>
+  </target>
+
+  <target name="test0PermissionsGetReplaced"
+                     depends="-setUp0Permissions">
+    <cmp:zip destfile="${dest}">
+      <cmp:arfileset src="${src}"
+                     includes="asf-logo.gif"/>
+    </cmp:zip>
+    <checkProperties dateTime="2009-07-31-20:11:12 +0200" mode="644"/>
+  </target>
+
+  <target name="testPreserve0Permissions"
+                     depends="-setUp0Permissions">
+    <cmp:zip destfile="${dest}" preserve0permissions="true">
+      <cmp:arfileset src="${src}"
+                     includes="asf-logo.gif"/>
+    </cmp:zip>
+    <checkProperties dateTime="2009-07-31-20:11:12 +0200" mode="0"/>
+  </target>
 </project>



Mime
View raw message