Browse Source

New attribute allows stripping of leading path spec from files before extracting them. PR 28911.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@677878 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 17 years ago
parent
commit
5019b99eb6
4 changed files with 50 additions and 0 deletions
  1. +6
    -0
      WHATSNEW
  2. +9
    -0
      docs/manual/CoreTasks/unzip.html
  3. +20
    -0
      src/main/org/apache/tools/ant/taskdefs/Expand.java
  4. +15
    -0
      src/tests/antunit/taskdefs/unzip-test.xml

+ 6
- 0
WHATSNEW View File

@@ -229,6 +229,12 @@ Other changes:
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
=============================================



+ 9
- 0
docs/manual/CoreTasks/unzip.html View File

@@ -116,6 +116,15 @@ archive.</p>
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>


+ 20
- 0
src/main/org/apache/tools/ant/taskdefs/Expand.java View File

@@ -67,6 +67,7 @@ public class Expand extends Task {
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 @@ public class Expand extends Task {
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 @@ public class Expand extends Task {
this.encoding = encoding;
}

/**
* Whether leading path separators should be stripped.
*
* @since Ant 1.8.0
*/
public void setStripAbsolutePathSpec(boolean b) {
stripAbsolutePathSpec = b;
}

}

+ 15
- 0
src/tests/antunit/taskdefs/unzip-test.xml View File

@@ -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>

Loading…
Cancel
Save