File file = download.getFile().getFile();
return file.isFile() ? file : download.getTempFile();
}
private boolean isChecksumValid(FileAndChecksum file) throws IOException {
Checksum expected = file.getExpectedChecksum();
if (expected == null)
return true;
Checksum actual = file.getActualChecksum();
boolean lastModifiedEquals = expected.getLastModified() == null ||
expected.getLastModified().equals(actual.getLastModified());
if (!lastModifiedEquals)
log.warning(format("%s has last modified %s but expected %s", file.getFile(), actual.getLastModified(), expected.getLastModified()));
boolean contentLengthEquals = expected.getContentLength() == null ||
expected.getContentLength().equals(actual.getContentLength());
if (!contentLengthEquals)
log.warning(format("%s has %d bytes but expected %d", file.getFile(), actual.getContentLength(), expected.getContentLength()));
boolean sha1Equals = expected.getSHA1() == null ||
expected.getSHA1().equals(actual.getSHA1());
if (!sha1Equals)
log.warning(format("%s has SHA-1 %s but expected %s", file.getFile(), actual.getSHA1(), expected.getSHA1()));
// TODO solve timezone problems first before making lastModifiedEquals relevant again
boolean valid = /*lastModifiedEquals &&*/ contentLengthEquals && sha1Equals;
if (valid)
log.info(format("%s has valid checksum", file.getFile()));
return valid;