diff --git a/WHATSNEW b/WHATSNEW index c7651a3f1..f26fe556e 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -26,6 +26,10 @@ Fixed bugs: * ignored the classpath when using the default TraX processor. Bugzilla Report 49271. + * 's totalproperty only worked reliably if the same file + name didn't occur inside more than one directory. + Bugzilla Report 36748. + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/Checksum.java b/src/main/org/apache/tools/ant/taskdefs/Checksum.java index 96bcf5907..5bc6aca68 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Checksum.java +++ b/src/main/org/apache/tools/ant/taskdefs/Checksum.java @@ -457,15 +457,7 @@ public class Checksum extends MatchingTask implements Condition { File directory; if (todir != null) { // 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(); // Create the directory, as it might not exist. directory.mkdirs(); @@ -559,8 +551,8 @@ public class Checksum extends MatchingTask implements Condition { File f2 = (File) o2; return f1 == null ? (f2 == null ? 0 : -1) : (f2 == null ? 1 - : f1.getName().compareTo(f2.getName()) - ); + : getRelativeFilePath(f1) + .compareTo(getRelativeFilePath(f2))); } }); // Loop over the checksums and generate a total hash. @@ -573,7 +565,7 @@ public class Checksum extends MatchingTask implements Condition { messageDigest.update(digest); // Add the file path - String fileName = (String) relativeFilePaths.get(src); + String fileName = getRelativeFilePath(src); messageDigest.update(fileName.getBytes()); } 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. * diff --git a/src/tests/antunit/taskdefs/checksum-test.xml b/src/tests/antunit/taskdefs/checksum-test.xml index d1ae33e81..022a6dbcf 100644 --- a/src/tests/antunit/taskdefs/checksum-test.xml +++ b/src/tests/antunit/taskdefs/checksum-test.xml @@ -36,12 +36,13 @@ https://issues.apache.org/bugzilla/show_bug.cgi?id=36748"> abc + def xyz + value="f4d688789d32e6ca6bc93c504dbc6b46"/>