Search in sources :

Example 1 with ChecksumFailureException

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);
    }
}
Also used : ChecksumFailureException(org.sonatype.aether.transfer.ChecksumFailureException) DefaultTransferEvent(org.sonatype.aether.util.listener.DefaultTransferEvent) IOException(java.io.IOException) File(java.io.File)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 ChecksumFailureException (org.sonatype.aether.transfer.ChecksumFailureException)1 DefaultTransferEvent (org.sonatype.aether.util.listener.DefaultTransferEvent)1