diff OrthancServer/Sources/ServerContext.cpp @ 4752:2f35e6b765e5

Fix orphaned attachments if bad revision number is provided
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 14 Jul 2021 17:21:15 +0200
parents da1edb7d6332
children b2417ac5055a 51ec061516c9
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerContext.cpp	Thu Jul 08 17:31:03 2021 +0200
+++ b/OrthancServer/Sources/ServerContext.cpp	Wed Jul 14 17:21:15 2021 +0200
@@ -1174,16 +1174,25 @@
     StorageAccessor accessor(area_, GetMetricsRegistry());
     FileInfo attachment = accessor.Write(data, size, attachmentType, compression, storeMD5_);
 
-    StoreStatus status = index_.AddAttachment(
-      newRevision, attachment, resourceId, hasOldRevision, oldRevision, oldMD5);
-    if (status != StoreStatus_Success)
+    try
     {
+      StoreStatus status = index_.AddAttachment(
+        newRevision, attachment, resourceId, hasOldRevision, oldRevision, oldMD5);
+      if (status != StoreStatus_Success)
+      {
+        accessor.Remove(attachment);
+        return false;
+      }
+      else
+      {
+        return true;
+      }
+    }
+    catch (OrthancException&)
+    {
+      // Fixed in Orthanc 1.9.6
       accessor.Remove(attachment);
-      return false;
-    }
-    else
-    {
-      return true;
+      throw;
     }
   }