Hash contents for checksums are now sorted before running (so that the

iterators are consistent)
This commit is contained in:
nathan 2017-09-14 23:03:15 +02:00
parent c5e891f5da
commit bde90d3d54
1 changed files with 9 additions and 1 deletions

View File

@ -22,7 +22,10 @@ import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.esotericsoftware.wildcard.Paths;
@ -178,6 +181,11 @@ class Hash {
names.addAll(path.getPaths());
}
// have to make sure the list is sorted, so the iterators are consistent
List<String> sortedNames = new ArrayList<String>(names.size());
sortedNames.addAll(names);
Collections.sort(sortedNames);
// hash of all files. faster than using java to hash files
MessageDigest sha1 = digestThreadLocal.get();
sha1.reset();
@ -187,7 +195,7 @@ class Hash {
int bytesRead = 0;
boolean found = false;
for (String name : names) {
for (String name : sortedNames) {
File file = new File(name);
if (file.isFile() && file.canRead()) {
found = true;