Browse Source

<checksum>'s totalproperty doesn't work with repeated file names. PR 36748

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@945023 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 15 years ago
parent
commit
3fb4745e70
3 changed files with 25 additions and 13 deletions
  1. +4
    -0
      WHATSNEW
  2. +19
    -12
      src/main/org/apache/tools/ant/taskdefs/Checksum.java
  3. +2
    -1
      src/tests/antunit/taskdefs/checksum-test.xml

+ 4
- 0
WHATSNEW View File

@@ -26,6 +26,10 @@ Fixed bugs:
* <xslt> ignored the classpath when using the default TraX processor. * <xslt> ignored the classpath when using the default TraX processor.
Bugzilla Report 49271. Bugzilla Report 49271.


* <checksum>'s totalproperty only worked reliably if the same file
name didn't occur inside more than one directory.
Bugzilla Report 36748.

Other changes: Other changes:
-------------- --------------




+ 19
- 12
src/main/org/apache/tools/ant/taskdefs/Checksum.java View File

@@ -457,15 +457,7 @@ public class Checksum extends MatchingTask implements Condition {
File directory; File directory;
if (todir != null) { if (todir != null) {
// A separate directory was explicitly declared // A separate directory was explicitly declared
String path = (String) relativeFilePaths.get(file);
if (path == null) {
//bug 37386. this should not occur, but it has, once.
throw new BuildException(
"Internal error: "
+ "relativeFilePaths could not match file"
+ file + "\n"
+ "please file a bug report on this");
}
String path = getRelativeFilePath(file);
directory = new File(todir, path).getParentFile(); directory = new File(todir, path).getParentFile();
// Create the directory, as it might not exist. // Create the directory, as it might not exist.
directory.mkdirs(); directory.mkdirs();
@@ -559,8 +551,8 @@ public class Checksum extends MatchingTask implements Condition {
File f2 = (File) o2; File f2 = (File) o2;
return f1 == null ? (f2 == null ? 0 : -1) return f1 == null ? (f2 == null ? 0 : -1)
: (f2 == null ? 1 : (f2 == null ? 1
: f1.getName().compareTo(f2.getName())
);
: getRelativeFilePath(f1)
.compareTo(getRelativeFilePath(f2)));
} }
}); });
// Loop over the checksums and generate a total hash. // Loop over the checksums and generate a total hash.
@@ -573,7 +565,7 @@ public class Checksum extends MatchingTask implements Condition {
messageDigest.update(digest); messageDigest.update(digest);


// Add the file path // Add the file path
String fileName = (String) relativeFilePaths.get(src);
String fileName = getRelativeFilePath(src);
messageDigest.update(fileName.getBytes()); messageDigest.update(fileName.getBytes());
} }
String totalChecksum = createDigestString(messageDigest.digest()); String totalChecksum = createDigestString(messageDigest.digest());
@@ -654,6 +646,21 @@ public class Checksum extends MatchingTask implements Condition {
} }
} }


/**
* @since Ant 1.8.2
*/
private String getRelativeFilePath(File f) {
String path = (String) relativeFilePaths.get(f);
if (path == null) {
//bug 37386. this should not occur, but it has, once.
throw new BuildException("Internal error: "
+ "relativeFilePaths could not match file "
+ f + "\n"
+ "please file a bug report on this");
}
return path;
}

/** /**
* Helper class for the format attribute. * Helper class for the format attribute.
* *


+ 2
- 1
src/tests/antunit/taskdefs/checksum-test.xml View File

@@ -36,12 +36,13 @@
https://issues.apache.org/bugzilla/show_bug.cgi?id=36748"> https://issues.apache.org/bugzilla/show_bug.cgi?id=36748">
<mkdir dir="${input}"/> <mkdir dir="${input}"/>
<echo file="${input}/a.txt">abc</echo> <echo file="${input}/a.txt">abc</echo>
<echo file="${input}/subdir/A.txt">def</echo>
<echo file="${input}/B.txt">xyz</echo> <echo file="${input}/B.txt">xyz</echo>
<checksum totalproperty="total"> <checksum totalproperty="total">
<fileset dir="${input}"/> <fileset dir="${input}"/>
</checksum> </checksum>
<au:assertPropertyEquals name="total" <au:assertPropertyEquals name="total"
value="709a9cf15c8834c59c7eeb07522cdf56"/>
value="f4d688789d32e6ca6bc93c504dbc6b46"/>
</target> </target>


</project> </project>

Loading…
Cancel
Save