mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
moved checksum path generation to separate method
This commit is contained in:
committed by
Jonathan Shook
parent
aa6326ffd8
commit
26bb89f2be
@@ -108,7 +108,7 @@ public class ResolverForNBIOCache implements ContentResolver {
|
||||
private boolean verifyChecksum(Path cachedFilePath, URLContent checksum) {
|
||||
try {
|
||||
String localChecksumStr = generateSHA256Checksum(cachedFilePath.toString());
|
||||
Path checksumPath = Path.of(cachedFilePath + ".sha256");
|
||||
Path checksumPath = checksumPath(cachedFilePath);
|
||||
Files.writeString(checksumPath, localChecksumStr);
|
||||
logger.debug(() -> "Generated local checksum and saved to cache at " + checksumPath);
|
||||
String remoteChecksum = new String(checksum.getInputStream().readAllBytes());
|
||||
@@ -160,7 +160,7 @@ public class ResolverForNBIOCache implements ContentResolver {
|
||||
private void cleanupCache(Path cachedFilePath) {
|
||||
if (!cachedFilePath.toFile().delete())
|
||||
logger.warn(() -> "Could not delete cached file " + cachedFilePath);
|
||||
Path checksumPath = Path.of(cachedFilePath + ".sha256");
|
||||
Path checksumPath = checksumPath(cachedFilePath);
|
||||
if (!checksumPath.toFile().delete())
|
||||
logger.warn(() -> "Could not delete cached checksum " + checksumPath);
|
||||
}
|
||||
@@ -240,7 +240,7 @@ public class ResolverForNBIOCache implements ContentResolver {
|
||||
}
|
||||
|
||||
private Path getOrCreateChecksum(Path cachedFilePath) {
|
||||
Path checksumPath = Path.of(cachedFilePath + ".sha256");
|
||||
Path checksumPath = checksumPath(cachedFilePath);
|
||||
if (!Files.isReadable(checksumPath)) {
|
||||
try {
|
||||
Files.writeString(checksumPath, generateSHA256Checksum(cachedFilePath.toString()));
|
||||
@@ -251,6 +251,10 @@ public class ResolverForNBIOCache implements ContentResolver {
|
||||
return checksumPath;
|
||||
}
|
||||
|
||||
private Path checksumPath(Path cachedFilePath) {
|
||||
return Path.of(cachedFilePath + ".sha256");
|
||||
}
|
||||
|
||||
private static String generateSHA256Checksum(String filePath) throws IOException, NoSuchAlgorithmException {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||
try (InputStream is = new FileInputStream(filePath)) {
|
||||
|
||||
Reference in New Issue
Block a user