ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r677878 - in /ant/core/trunk: WHATSNEW docs/manual/CoreTasks/unzip.html src/main/org/apache/tools/ant/taskdefs/Expand.java src/tests/antunit/taskdefs/unzip-test.xml
Date Fri, 18 Jul 2008 10:51:31 GMT
Author: bodewig
Date: Fri Jul 18 03:51:30 2008
New Revision: 677878

URL: http://svn.apache.org/viewvc?rev=677878&view=rev
Log:
New attribute allows stripping of leading path spec from files before extracting them.  PR
28911.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/CoreTasks/unzip.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Expand.java
    ant/core/trunk/src/tests/antunit/taskdefs/unzip-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=677878&r1=677877&r2=677878&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Jul 18 03:51:30 2008
@@ -229,6 +229,12 @@
    make the task fail the build if it tries to extract an empty
    archive.
 
+ * <unzip> and <untar> have a new attribute stripAbsolutePathSpec.
+   When set to true, Ant will remove any leading path separator from
+   the archived entry's name before extracting it (making the name a
+   relative file name).
+   Bugzilla Report 28911.
+
 Changes from Ant 1.7.0 TO Ant 1.7.1
 =============================================
 

Modified: ant/core/trunk/docs/manual/CoreTasks/unzip.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/unzip.html?rev=677878&r1=677877&r2=677878&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/unzip.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/unzip.html Fri Jul 18 03:51:30 2008
@@ -116,6 +116,15 @@
       error. <em>since Ant 1.8.0</em></td>
     <td valign="top" align="center">No, defaults to false</td>
   </tr>
+  <tr>
+    <td valign="top">stripAbsolutePathSpec</td>
+    <td valign="top">whether Ant should remove leading '/' or '\'
+      characters from the extracted file name before extracing it.
+      Note that this changes the entry's name before applying
+      include/exclude patterns and before using the nested mappers (if
+      any).  <em>since Ant 1.8.0</em></td>
+    <td valign="top" align="center">No, defaults to false</td>
+  </tr>
 </table>
 <h3>Examples</h3>
 <pre>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Expand.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Expand.java?rev=677878&r1=677877&r2=677878&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Expand.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Expand.java Fri Jul 18 03:51:30
2008
@@ -67,6 +67,7 @@
     private Union resources = new Union();
     private boolean resourcesSpecified = false;
     private boolean failOnEmptyArchive = false;
+    private boolean stripAbsolutePathSpec = false;
 
     private static final String NATIVE_ENCODING = "native-encoding";
 
@@ -232,9 +233,19 @@
                                boolean isDirectory, FileNameMapper mapper)
                                throws IOException {
 
+        if (stripAbsolutePathSpec && entryName.length() > 0
+            && (entryName.charAt(0) == File.separatorChar
+                || entryName.charAt(0) == '/'
+                || entryName.charAt(0) == '\\')) {
+            log("stripped absolute path spec from " + entryName,
+                Project.MSG_VERBOSE);
+            entryName = entryName.substring(1);
+        }
+
         if (patternsets != null && patternsets.size() > 0) {
             String name = entryName.replace('/', File.separatorChar)
                 .replace('\\', File.separatorChar);
+
             boolean included = false;
             Set includePatterns = new HashSet();
             Set excludePatterns = new HashSet();
@@ -432,4 +443,13 @@
         this.encoding = encoding;
     }
 
+    /**
+     * Whether leading path separators should be stripped.
+     *
+     * @since Ant 1.8.0
+     */
+    public void setStripAbsolutePathSpec(boolean b) {
+        stripAbsolutePathSpec = b;
+    }
+
 }

Modified: ant/core/trunk/src/tests/antunit/taskdefs/unzip-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/unzip-test.xml?rev=677878&r1=677877&r2=677878&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/unzip-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/unzip-test.xml Fri Jul 18 03:51:30 2008
@@ -36,4 +36,19 @@
       <unzip src="broken_cd.zip" dest="${dest.dir}"/>
     </au:expectfailure>
   </target>
+
+  <!-- Issue 28911 -->
+  <target name="testStrippingOfPathsep">
+    <property name="in" location="${dest.dir}/input"/>
+    <property name="out" location="${dest.dir}/out"/>
+    <mkdir dir="${in}"/>
+    <mkdir dir="${out}"/>
+    <touch file="${in}/file"/>
+    <zip destfile="${dest.dir}/a.zip">
+      <zipfileset dir="${dest.dir}/input" prefix="/foo"/>
+    </zip>
+    <unzip src="${dest.dir}/a.zip" stripAbsolutePathSpec="true"
+           dest="${out}"/>
+    <au:assertFileExists file="${out}/foo/file"/>
+  </target>
 </project>



Mime
View raw message