diff OrthancFramework/Sources/Compression/ZipWriter.cpp @ 5560:c80dbbae3f60

Removed potential PHI from the logs when Orthanc encounters an error while creating a zip file
author Alain Mazy <am@orthanc.team>
date Mon, 22 Apr 2024 10:50:33 +0200
parents 48b8dae6dc77
children f7adfb22e20e
line wrap: on
line diff
--- a/OrthancFramework/Sources/Compression/ZipWriter.cpp	Mon Apr 22 10:39:33 2024 +0200
+++ b/OrthancFramework/Sources/Compression/ZipWriter.cpp	Mon Apr 22 10:50:33 2024 +0200
@@ -553,7 +553,7 @@
       if (!pimpl_->file_)
       {
         throw OrthancException(ErrorCode_CannotWriteFile,
-                               "Cannot create new ZIP archive: " + path_);
+                               "Cannot create new ZIP archive");  // we do not log the path anymore since it can contain PHI
       }
     }
   }
@@ -632,10 +632,10 @@
                                    compressionLevel_);
     }
 
-    if (result != 0)
+    if (result != ZIP_OK)
     {
       throw OrthancException(ErrorCode_CannotWriteFile,
-                             "Cannot add new file inside ZIP archive: " + std::string(path));
+                             "Cannot add new file inside ZIP archive - error code = " + boost::lexical_cast<std::string>(result)); // we do not log the path anymore since it can contain PHI
     }
 
     hasFileInZip_ = true;
@@ -666,10 +666,11 @@
     {
       int bytes = static_cast<int32_t>(length <= maxBytesInAStep ? length : maxBytesInAStep);
 
-      if (zipWriteInFileInZip(pimpl_->file_, p, bytes))
+      int result = zipWriteInFileInZip(pimpl_->file_, p, bytes);
+      if (result != ZIP_OK)
       {
         throw OrthancException(ErrorCode_CannotWriteFile,
-                               "Cannot write data to ZIP archive: " + path_);
+                               "Cannot write data to ZIP archive - error code =" + boost::lexical_cast<std::string>(result));  // we do not log the path anymore since it can contain PHI
       }
       
       p += bytes;