From 88faf22939ff002c484e3676e9dbe8a6c1bb8eae Mon Sep 17 00:00:00 2001 From: Andreas Romeyke <andreas.romeyke@slub-dresden.de> Date: Mon, 3 Jul 2017 11:41:51 +0200 Subject: [PATCH] - fixity.setResult expects boolean - added support for SHA256 - bug fix: added try-catch to catch an exception if fixity.getValue() fails --- .../plugin/storage/nfs/SLUBStoragePlugin.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/java/org/slub/rosetta/dps/repository/plugin/storage/nfs/SLUBStoragePlugin.java b/java/org/slub/rosetta/dps/repository/plugin/storage/nfs/SLUBStoragePlugin.java index 174ed85..65cdf57 100644 --- a/java/org/slub/rosetta/dps/repository/plugin/storage/nfs/SLUBStoragePlugin.java +++ b/java/org/slub/rosetta/dps/repository/plugin/storage/nfs/SLUBStoragePlugin.java @@ -89,22 +89,24 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { is = retrieveEntity(storedEntityIdentifier, isRelativePath); Checksummer checksummer = new Checksummer(is, true, true, true); for (Fixity fixity : fixities) { - fixity.setResult(null); + fixity.setResult(false); log.info("SLUBStoragePlugin.checkFixity() getAlgorithm=" + fixity.getAlgorithm()); log.info("SLUBStoragePlugin.checkFixity() FixityAlgorithm.MD5=" + Fixity.FixityAlgorithm.MD5.toString()); log.info("SLUBStoragePlugin.checkFixity() FixityAlgorithm.SHA1=" + Fixity.FixityAlgorithm.SHA1.toString()); + log.info("SLUBStoragePlugin.checkFixity() FixityAlgorithm.SHA256=" + Fixity.FixityAlgorithm.SHA256.toString()); log.info("SLUBStoragePlugin.checkFixity() FixityAlgorithm.CRC32=" + Fixity.FixityAlgorithm.CRC32.toString()); /* TODO: with upcoming versions of Rosetta, recheck need of * Workaround for fixity.getAlgorithm() */ String algorithm = fixity.getAlgorithm().toUpperCase(); // workaround, because fixity.getAlgorithm() returns lowercase string if ( (!Fixity.FixityAlgorithm.MD5.toString().equals(algorithm)) && - (!Fixity.FixityAlgorithm.SHA1.toString().equals(algorithm)) && - (!Fixity.FixityAlgorithm.CRC32.toString().equals(algorithm)) - ) { + (!Fixity.FixityAlgorithm.SHA1.toString().equals(algorithm)) && + (!Fixity.FixityAlgorithm.SHA256.toString().equals(algorithm)) && + (!Fixity.FixityAlgorithm.CRC32.toString().equals(algorithm)) + ) { result = checkFixityByPlugin(fixity, storedEntityIdentifier, isRelativePath, result); } else { - log.info("SLUBStoragePlugin.checkFixity() calcMD5|calcSHA1|calcCRC32=true"); + log.info("SLUBStoragePlugin.checkFixity() calcMD5|calcSHA1|calcCRC32|calcSHA256=true"); int checksummerAlgorithmIndex = getChecksummerAlgorithmIndex(algorithm); log.info("SLUBStoragePlugin.checkFixity() checksummerAlgorithmIndex=" + checksummerAlgorithmIndex); if (checksummerAlgorithmIndex != -1) @@ -157,8 +159,14 @@ public class SLUBStoragePlugin extends AbstractStorageHandler { private boolean checkFixityByPlugin(Fixity fixity, String storedEntityIdentifier, boolean isRelativePath, boolean result) throws Exception { log.info("SLUBStoragePlugin.checkFixity() another fixity"); log.info("SLUBStoragePlugin.checkFixity() pluginname=" + fixity.getPluginName()); - String oldValue = fixity.getValue(); - log.info("SLUBStoragePlugin.checkFixity() oldvalue=" + oldValue); + String oldValue = ""; + try { + oldValue = fixity.getValue(); + log.info("SLUBStoragePlugin.checkFixity() oldvalue=" + oldValue); + } + catch (Exception e) { + log.warn("SLUBStoragePlugin failed to get previous fixity value for file " + file.getPath(), e.getMessage()); + } fixity.setValue(getChecksumUsingPlugin(isRelativePath ? getLocalFilePath(storedEntityIdentifier) : storedEntityIdentifier, fixity.getPluginName(), oldValue)); fixity.setResult((oldValue == null) || (oldValue.equals(fixity.getValue()))); log.info("SLUBStoragePlugin.checkFixity() newvalue=" + fixity.getValue()); -- GitLab