use of org.sonatype.aether.transfer.ChecksumFailureException in project sonatype-aether by sonatype.
the class FileRepositoryWorker method verifyChecksum.
private void verifyChecksum(File src) throws ChecksumFailureException, IOException, TransferCancelledException {
if (RepositoryPolicy.CHECKSUM_POLICY_IGNORE.equals(transfer.getChecksumPolicy())) {
return;
}
Map<String, Object> crcs = ChecksumUtils.calc(src, checksumAlgos.keySet());
boolean verified = false;
try {
for (Entry<String, String> entry : checksumAlgos.entrySet()) {
try {
String sum = ChecksumUtils.read(new File(src.getPath() + entry.getValue()));
verified = sum.equalsIgnoreCase(crcs.get(entry.getKey()).toString());
if (!verified) {
throw new ChecksumFailureException(sum, crcs.get(entry.getKey()).toString());
}
break;
} catch (IOException e) {
// skip verify - try next algorithm
continue;
}
}
// all algorithms checked
if (!verified) {
throw new ChecksumFailureException("no supported algorithms found");
}
} catch (ChecksumFailureException e) {
if (RepositoryPolicy.CHECKSUM_POLICY_FAIL.equals(transfer.getChecksumPolicy())) {
throw e;
}
DefaultTransferEvent event = newEvent(transfer);
event.setException(e);
catapult.fireCorrupted(event);
}
}
Aggregations