From 584289f68f070874b0d18f0b6757ac25399a37df Mon Sep 17 00:00:00 2001
From: Andreas Romeyke <andreas.romeyke@slub-dresden.de>
Date: Thu, 14 Mar 2024 14:45:18 +0100
Subject: [PATCH] - bugfix, new fixity value should only be set in
 Fixity-object, if   a) old value is null or   b) newvalue is equivalent to
 old value   otherwise it results in logic error if a copy from operational to
   permanent fails first and will be triggered again

---
 .../plugin/storage/nfs/SLUBStoragePlugin.java | 27 +++++++++++++------
 1 file changed, 19 insertions(+), 8 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 9c0c45e..7e29eed 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
@@ -326,12 +326,17 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
         contractAssertIsRelativePath(storedEntityIdentifier);
         InputStream is = retrieveEntity(storedEntityIdentifier);
         Checksummer checksummer = new Checksummer(is, true, true, true, true);
-        fixity.setValue(checksummer.getChecksum(algorithm));
-        var newValue = fixity.getValue();
-        //log.debug("SLUBStoragePlugin.checkFixityByBuiltin() newvalue=" + newValue);
-        fixity.setResult((oldValue == null) || (oldValue.equalsIgnoreCase(newValue)));
-        boolean result = fixity.getResult();
         is.close();
+        String newValue = checksummer.getChecksum(algorithm);
+        boolean result = (oldValue == null) || (oldValue.equals(newValue));
+        if (result) {
+            /* only if no old value or newvalue = oldvalue set new value,
+             * this prevents errors in output logic if a copy from operational to
+             * permanent fails first and will be triggered again.
+             */
+            fixity.setValue(newValue);
+        }
+        fixity.setResult(result);
         long endtime = System.currentTimeMillis();
         log.info("SLUBStoragePlugin.checkFixityByBuiltin(), end checksum calc for pathname='" + absolute_storedEntityIdentifier.filestring() + "'"
                 + " algorithm=" + algorithm
@@ -387,12 +392,18 @@ public class SLUBStoragePlugin extends AbstractStorageHandler {
         } catch  (Exception e) {
             log.error("SLUBStoragePlugin.checkFixityByPlugin() exception in getChecksumUsingPlugin("+absolute_storedEntityIdentifier.filestring() + ", "+ pluginname + ", " + oldValue +"), " + e.getMessage() );
         }
-        fixity.setValue(newValue);
+        boolean result = (oldValue == null) || (oldValue.equals(newValue));
+        if (result) {
+            /* only if no old value or newvalue = oldvalue set new value,
+             * this prevents errors in output logic if a copy from operational to
+             * permanent fails first and will be triggered again.
+             */
+            fixity.setValue(newValue);
+        }
+        fixity.setResult(result);
         /* HINT: if plugin name is still empty a java.lang.NullPointerException gets thrown
                  Rosetta will handle it and let us know (creates technical issue in workbench)
          */
-        fixity.setResult((oldValue == null) || (oldValue.equals(newValue)));
-        boolean result = fixity.getResult();
         long endtime = System.currentTimeMillis();
         log.info("SLUBStoragePlugin.checkFixityByPlugin(), end checksum calc for pathname='" + absolute_storedEntityIdentifier.filestring() + "'"
                 + " plugin=" + pluginname
-- 
GitLab