The Tar task doesn't use the dir attribute for tarfilesets when
determining if the tar file is up to date, so updated files or new
files never get added. Attached is a fix and test case.
Rod
Index: tar.xml
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/etc/testcases/taskdefs/tar.xml,v
retrieving revision 1.9
diff -u -r1.9 tar.xml
--- tar.xml 4 Feb 2002 20:44:16 -0000 1.9
+++ tar.xml 11 Mar 2002 20:53:26 -0000
@@ -53,7 +53,24 @@
<untar src="test8.tar" dest="."/>
</target>
- <target name="cleanup">
+ <target name="test9">
+ <touch file="test9a.txt"/>
+ <tar destfile="test9.tar">
+ <tarfileset dir=".">
+ <include name="test9*.txt"/>
+ </tarfileset>
+ </tar>
+ <sleep seconds="5"/>
+ <touch file="test9b.txt"/>
+ <tar destfile="test9.tar">
+ <tarfileset dir=".">
+ <include name="test9*.txt"/>
+ </tarfileset>
+ </tar>
+ <untar src="test9.tar" dest="test9dir"/>
+ </target>
+
+ <target name="cleanup">
<delete file="test4.tar"/>
<delete file="test5.tar"/>
<delete file="asf-logo.gif.tar"/>
@@ -63,6 +80,10 @@
<delete file="test7.tar"/>
<delete file="test8.tar"/>
<delete file="test8.xml"/>
+ <delete file="test9.tar"/>
+ <delete file="test9a.txt"/>
+ <delete file="test9b.txt"/>
+ <delete dir="test9dir"/>
</target>
<target name="feather">
Index: Tar.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tar.java,v
retrieving revision 1.26
diff -u -r1.26 Tar.java
--- Tar.java 3 Mar 2002 01:46:20 -0000 1.26
+++ Tar.java 11 Mar 2002 21:00:17 -0000
@@ -227,8 +227,9 @@
for (Enumeration e = filesets.elements(); e.hasMoreElements();) {
TarFileSet fs = (TarFileSet)e.nextElement();
String[] files = fs.getFiles(project);
+ File dir = (baseDir == null) ? fs.getDir(project) : baseDir;
- if (!archiveIsUpToDate(files)) {
+ if (!archiveIsUpToDate(dir, files)) {
upToDate = false;
}
@@ -305,11 +306,11 @@
if (vPath.length() <= 0) {
return;
}
-
+
if (file.isDirectory() && !vPath.endsWith("/")) {
vPath += "/";
}
-
+
String prefix = tarFileSet.getPrefix();
// '/' is appended for compatibility with the zip task.
if (prefix.length() > 0 && !prefix.endsWith("/")) {
@@ -323,7 +324,7 @@
if (l <= 1) {
// we would end up adding "" to the archive
return;
- }
+ }
vPath = vPath.substring(1, l);
}
@@ -377,11 +378,11 @@
}
}
- protected boolean archiveIsUpToDate(String[] files) {
+ protected boolean archiveIsUpToDate(File dir, String[] files) {
SourceFileScanner sfs = new SourceFileScanner(this);
MergingMapper mm = new MergingMapper();
mm.setTo(tarFile.getAbsolutePath());
- return sfs.restrict(files, baseDir, null, mm).length == 0;
+ return sfs.restrict(files, dir, null, mm).length == 0;
}
public static class TarFileSet extends FileSet {
@@ -394,7 +395,7 @@
private String prefix = "";
private String fullpath = "";
private boolean preserveLeadingSlashes = false;
-
+
public TarFileSet(FileSet fileset) {
super(fileset);
}
Index: TarTest.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/TarTest.java,v
retrieving revision 1.9
diff -u -r1.9 TarTest.java
--- TarTest.java 4 Feb 2002 20:44:16 -0000 1.9
+++ TarTest.java 11 Mar 2002 20:52:13 -0000
@@ -124,6 +124,15 @@
}
}
+ public void test9() {
+ executeTarget("test9");
+ java.io.File f1
+ = new
java.io.File("src/etc/testcases/taskdefs/test9dir/test9b.txt");
+ if (!f1.exists()) {
+ fail("Updating a tar file failed");
+ }
+ }
+
public void tearDown() {
executeTarget("cleanup");
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>