Browse Source

Add overwrite attribute to unjar/war/zip and untar - if set to false,

files newer than the entries in the archive will not be replaced.

Default is true for backwards compatibility.

PR: 1667


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269394 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
9e9d8fecc5
5 changed files with 58 additions and 5 deletions
  1. +4
    -0
      WHATSNEW
  2. +7
    -0
      docs/manual/CoreTasks/untar.html
  3. +7
    -0
      docs/manual/CoreTasks/unzip.html
  4. +20
    -3
      src/main/org/apache/tools/ant/taskdefs/Expand.java
  5. +20
    -2
      src/main/org/apache/tools/ant/taskdefs/Untar.java

+ 4
- 0
WHATSNEW View File

@@ -127,6 +127,10 @@ Other changes:
* <taskdef> can now define several tasks at once, reading the * <taskdef> can now define several tasks at once, reading the
name/classname pairs from a property file or resource. name/classname pairs from a property file or resource.


* <unzip/unjar/unwar> and <untar> now have an overwrite attribute that
defaults to true. If set to false, files that are newer than the
files in the archive will not be replaced.

Fixed bugs: Fixed bugs:
----------- -----------




+ 7
- 0
docs/manual/CoreTasks/untar.html View File

@@ -35,6 +35,13 @@ carried from tarfile.</p>
<td valign="top">directory where to store the expanded files.</td> <td valign="top">directory where to store the expanded files.</td>
<td align="center" valign="top">Yes</td> <td align="center" valign="top">Yes</td>
</tr> </tr>
<tr>
<td valign="top">overwrite</td>
<td valign="top"> Overwrite files, even if they are newer than the
corresponding entries in the archive (true or false, default is
true).</td>
<td align="center" valign="top">No</td>
</tr>
</table> </table>
<h3>Examples</h3> <h3>Examples</h3>
<blockquote> <blockquote>


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

@@ -30,6 +30,13 @@ carried from zipfile.</p>
<td valign="top">directory where to store the expanded files.</td> <td valign="top">directory where to store the expanded files.</td>
<td align="center" valign="top">Yes</td> <td align="center" valign="top">Yes</td>
</tr> </tr>
<tr>
<td valign="top">overwrite</td>
<td valign="top">Overwrite files, even if they are newer than the
corresponding entries in the archive (true or false, default is
true).</td>
<td align="center" valign="top">No</td>
</tr>
</table> </table>
<h3>Examples</h3> <h3>Examples</h3>
<blockquote> <blockquote>


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

@@ -66,6 +66,8 @@ import java.util.zip.*;
public class Expand extends MatchingTask { public class Expand extends MatchingTask {
private File dest; // req private File dest; // req
private File source; // req private File source; // req

private boolean overwrite = true;
/** /**
* Do the work. * Do the work.
@@ -104,8 +106,6 @@ public class Expand extends MatchingTask {
else { else {
expandFile(touch, source, dest); expandFile(touch, source, dest);
} }

} }


private void expandFile(Touch touch, File srcF, File dir) { private void expandFile(Touch touch, File srcF, File dir) {
@@ -119,7 +119,15 @@ public class Expand extends MatchingTask {
while ((ze = zis.getNextEntry()) != null) { while ((ze = zis.getNextEntry()) != null) {
File f = new File(dir, project.translatePath(ze.getName())); File f = new File(dir, project.translatePath(ze.getName()));
try { try {
log("expand-file " + ze.getName() , Project.MSG_VERBOSE );
if (!overwrite && f.exists()
&& f.lastModified() >= ze.getTime()) {
log("Skipping " + f + " as it is up-to-date",
Project.MSG_DEBUG);
continue;
}
log("expanding " + ze.getName() + " to "+ f,
Project.MSG_VERBOSE);
// create intermediary directories - sometimes zip don't add them // create intermediary directories - sometimes zip don't add them
File dirF=new File(f.getParent()); File dirF=new File(f.getParent());
dirF.mkdirs(); dirF.mkdirs();
@@ -179,4 +187,13 @@ public class Expand extends MatchingTask {
public void setSrc(File s) { public void setSrc(File s) {
this.source = s; this.source = s;
} }

/**
* Should we overwrite files in dest, even if they are newer than
* the corresponding entries in the archive?
*/
public void setOverwrite(boolean b) {
overwrite = b;
}

} }

+ 20
- 2
src/main/org/apache/tools/ant/taskdefs/Untar.java View File

@@ -69,6 +69,8 @@ public class Untar extends Task {
private File dest; // req private File dest; // req
private File source; // req private File source; // req


private boolean overwrite = true;
/** /**
* Do the work. * Do the work.
* *
@@ -105,8 +107,15 @@ public class Untar extends Task {
while ((te = tis.getNextEntry()) != null) { while ((te = tis.getNextEntry()) != null) {
try { try {
File f = new File(dir, project.translatePath(te.getName())); File f = new File(dir, project.translatePath(te.getName()));
log("expand-file " + te.getName(), Project.MSG_VERBOSE );
// create intermediary directories - sometimes tar don't add them
if (!overwrite && f.exists()
&& f.lastModified() >= te.getModTime().getTime()) {
log("Skipping " + f + " as it is up-to-date",
Project.MSG_DEBUG);
continue;
}
log("expanding " + te.getName() + " to "+ f,
Project.MSG_VERBOSE);
File dirF=new File(f.getParent()); File dirF=new File(f.getParent());
dirF.mkdirs(); dirF.mkdirs();


@@ -166,4 +175,13 @@ public class Untar extends Task {
public void setSrc(File s) { public void setSrc(File s) {
this.source = s; this.source = s;
} }

/**
* Should we overwrite files in dest, even if they are newer than
* the corresponding entries in the archive?
*/
public void setOverwrite(boolean b) {
overwrite = b;
}

} }

Loading…
Cancel
Save