From 5e289178b2416cea16d1aeb7585e5758bf6df377 Mon Sep 17 00:00:00 2001 From: Jan van Mansum Date: Sat, 24 Feb 2018 18:57:35 +0100 Subject: [PATCH] Bugfix --- .gitignore | 3 +++ .../repository/bagit/verify/BagVerifier.java | 20 ++++++++++++------- .../bagit/verify/CheckManifestHashesTask.java | 5 +++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 16f5749a0..bc0761bc7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ bagit-conformance-suite/ .classpath .gradle/ .DS_Store +/.idea +*.iml +/out diff --git a/src/main/java/gov/loc/repository/bagit/verify/BagVerifier.java b/src/main/java/gov/loc/repository/bagit/verify/BagVerifier.java index d0f50c86e..0d8758e64 100644 --- a/src/main/java/gov/loc/repository/bagit/verify/BagVerifier.java +++ b/src/main/java/gov/loc/repository/bagit/verify/BagVerifier.java @@ -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; @@ -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 exceptions = new ArrayList<>(); - + final List tasks = new ArrayList<>(); + for(final Entry 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 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){ diff --git a/src/main/java/gov/loc/repository/bagit/verify/CheckManifestHashesTask.java b/src/main/java/gov/loc/repository/bagit/verify/CheckManifestHashesTask.java index fbe82a37e..4957df5ad 100644 --- a/src/main/java/gov/loc/repository/bagit/verify/CheckManifestHashesTask.java +++ b/src/main/java/gov/loc/repository/bagit/verify/CheckManifestHashesTask.java @@ -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; @@ -30,11 +31,11 @@ public class CheckManifestHashesTask implements Runnable { private final List exceptions; private final String algorithm; - public CheckManifestHashesTask(final Entry entry, final String algorithm, final CountDownLatch latch, final List exceptions) { + public CheckManifestHashesTask(final Entry entry, final String algorithm, final CountDownLatch latch) { this.entry = entry; this.algorithm = algorithm; this.latch = latch; - this.exceptions = exceptions; + this.exceptions = new ArrayList<>(); } @Override