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.
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:
--------------



+ 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;
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.
*


+ 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">
<mkdir dir="${input}"/>
<echo file="${input}/a.txt">abc</echo>
<echo file="${input}/subdir/A.txt">def</echo>
<echo file="${input}/B.txt">xyz</echo>
<checksum totalproperty="total">
<fileset dir="${input}"/>
</checksum>
<au:assertPropertyEquals name="total"
value="709a9cf15c8834c59c7eeb07522cdf56"/>
value="f4d688789d32e6ca6bc93c504dbc6b46"/>
</target>

</project>

Loading…
Cancel
Save