git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@677878 13f79535-47bb-0310-9956-ffa450edef68master
@@ -229,6 +229,12 @@ Other changes: | |||||
make the task fail the build if it tries to extract an empty | make the task fail the build if it tries to extract an empty | ||||
archive. | 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 | Changes from Ant 1.7.0 TO Ant 1.7.1 | ||||
============================================= | ============================================= | ||||
@@ -116,6 +116,15 @@ archive.</p> | |||||
error. <em>since Ant 1.8.0</em></td> | error. <em>since Ant 1.8.0</em></td> | ||||
<td valign="top" align="center">No, defaults to false</td> | <td valign="top" align="center">No, defaults to false</td> | ||||
</tr> | </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> | </table> | ||||
<h3>Examples</h3> | <h3>Examples</h3> | ||||
<pre> | <pre> | ||||
@@ -67,6 +67,7 @@ public class Expand extends Task { | |||||
private Union resources = new Union(); | private Union resources = new Union(); | ||||
private boolean resourcesSpecified = false; | private boolean resourcesSpecified = false; | ||||
private boolean failOnEmptyArchive = false; | private boolean failOnEmptyArchive = false; | ||||
private boolean stripAbsolutePathSpec = false; | |||||
private static final String NATIVE_ENCODING = "native-encoding"; | private static final String NATIVE_ENCODING = "native-encoding"; | ||||
@@ -232,9 +233,19 @@ public class Expand extends Task { | |||||
boolean isDirectory, FileNameMapper mapper) | boolean isDirectory, FileNameMapper mapper) | ||||
throws IOException { | 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) { | if (patternsets != null && patternsets.size() > 0) { | ||||
String name = entryName.replace('/', File.separatorChar) | String name = entryName.replace('/', File.separatorChar) | ||||
.replace('\\', File.separatorChar); | .replace('\\', File.separatorChar); | ||||
boolean included = false; | boolean included = false; | ||||
Set includePatterns = new HashSet(); | Set includePatterns = new HashSet(); | ||||
Set excludePatterns = new HashSet(); | Set excludePatterns = new HashSet(); | ||||
@@ -432,4 +443,13 @@ public class Expand extends Task { | |||||
this.encoding = encoding; | this.encoding = encoding; | ||||
} | } | ||||
/** | |||||
* Whether leading path separators should be stripped. | |||||
* | |||||
* @since Ant 1.8.0 | |||||
*/ | |||||
public void setStripAbsolutePathSpec(boolean b) { | |||||
stripAbsolutePathSpec = b; | |||||
} | |||||
} | } |
@@ -36,4 +36,19 @@ | |||||
<unzip src="broken_cd.zip" dest="${dest.dir}"/> | <unzip src="broken_cd.zip" dest="${dest.dir}"/> | ||||
</au:expectfailure> | </au:expectfailure> | ||||
</target> | </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> | </project> |