Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ bagit-conformance-suite/
.classpath
.gradle/
.DS_Store
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related, but a nice to have for anyone contributing who uses IntelliJ.

/.idea
*.iml
/out
20 changes: 13 additions & 7 deletions src/main/java/gov/loc/repository/bagit/verify/BagVerifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Map.Entry;
Expand Down Expand Up @@ -151,17 +152,22 @@ public void isValid(final Bag bag, final boolean ignoreHiddenFiles) throws IOExc
void checkHashes(final Manifest manifest) throws CorruptChecksumException, InterruptedException, VerificationException{
final CountDownLatch latch = new CountDownLatch( manifest.getFileToChecksumMap().size());

//TODO maybe return all of these at some point...
//if that is ever the case make sure to use Collections.synchronizedCollection(new ArrayList<>())
//we aren't doing it now because it is a huge performance hit for little value
final List<Exception> exceptions = new ArrayList<>();

final List<CheckManifestHashesTask> tasks = new ArrayList<>();

for(final Entry<Path, String> entry : manifest.getFileToChecksumMap().entrySet()){
executor.execute(new CheckManifestHashesTask(entry, manifest.getAlgorithm().getMessageDigestName(), latch, exceptions));
final CheckManifestHashesTask task = new CheckManifestHashesTask(entry, manifest.getAlgorithm().getMessageDigestName(), latch);
tasks.add(task);
executor.execute(task);
}

latch.await();


//TODO maybe return all of these at some point...
final List<Exception> exceptions = new LinkedList<>();
for (final CheckManifestHashesTask task: tasks) {
exceptions.addAll(task.getExceptions());
}

if(!exceptions.isEmpty()){
final Exception e = exceptions.get(0);
if(e instanceof CorruptChecksumException){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.nio.file.Path;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Map.Entry;
Expand All @@ -30,11 +31,11 @@ public class CheckManifestHashesTask implements Runnable {
private final List<Exception> exceptions;
private final String algorithm;

public CheckManifestHashesTask(final Entry<Path, String> entry, final String algorithm, final CountDownLatch latch, final List<Exception> exceptions) {
public CheckManifestHashesTask(final Entry<Path, String> entry, final String algorithm, final CountDownLatch latch) {
this.entry = entry;
this.algorithm = algorithm;
this.latch = latch;
this.exceptions = exceptions;
this.exceptions = new ArrayList<>();
}

@Override
Expand Down