changeset 111:407bd022b0cf

in /move-storage: now detecting if file should be moved or not
author Alain Mazy <am@osimis.io>
date Tue, 10 Oct 2023 16:11:18 +0200
parents 37a4b8e2577f
children f2c242a6f8ab
files Aws/AwsS3StoragePlugin.cpp Azure/AzureBlobStoragePlugin.cpp Common/FileSystemStorage.cpp Common/FileSystemStorage.h Common/IStorage.h Common/MoveStorageJob.cpp Google/GoogleStoragePlugin.cpp NEWS
diffstat 8 files changed, 34 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Aws/AwsS3StoragePlugin.cpp	Tue Oct 10 15:40:36 2023 +0200
+++ b/Aws/AwsS3StoragePlugin.cpp	Tue Oct 10 16:11:18 2023 +0200
@@ -62,6 +62,7 @@
   virtual IWriter* GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled);
   virtual IReader* GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled);
   virtual void DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled);
+  virtual bool HasFileExists() {return false;};
 };
 
 
--- a/Azure/AzureBlobStoragePlugin.cpp	Tue Oct 10 15:40:36 2023 +0200
+++ b/Azure/AzureBlobStoragePlugin.cpp	Tue Oct 10 16:11:18 2023 +0200
@@ -46,6 +46,7 @@
   virtual IWriter* GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled);
   virtual IReader* GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled);
   virtual void DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled);
+  virtual bool HasFileExists() {return false;};
 };
 
 
--- a/Common/FileSystemStorage.cpp	Tue Oct 10 15:40:36 2023 +0200
+++ b/Common/FileSystemStorage.cpp	Tue Oct 10 16:11:18 2023 +0200
@@ -146,4 +146,12 @@
 
 }
 
+bool FileSystemStoragePlugin::FileExists(const std::string& uuid, OrthancPluginContentType type, bool encryptionEnabled)
+{
+  namespace fs = boost::filesystem;
 
+  fs::path path = BaseStorage::GetOrthancFileSystemPath(uuid, fileSystemRootPath_);
+
+  return Orthanc::SystemToolbox::IsExistingFile(path.string());
+}
+
--- a/Common/FileSystemStorage.h	Tue Oct 10 15:40:36 2023 +0200
+++ b/Common/FileSystemStorage.h	Tue Oct 10 16:11:18 2023 +0200
@@ -70,4 +70,7 @@
   virtual IStorage::IWriter* GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled);
   virtual IStorage::IReader* GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled);
   virtual void DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled);
+
+  virtual bool HasFileExists() {return true;};
+  virtual bool FileExists(const std::string& uuid, OrthancPluginContentType type, bool encryptionEnabled);
 };
\ No newline at end of file
--- a/Common/IStorage.h	Tue Oct 10 15:40:36 2023 +0200
+++ b/Common/IStorage.h	Tue Oct 10 16:11:18 2023 +0200
@@ -80,4 +80,7 @@
   virtual void DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) = 0;  // returns true only if 100% sure that the file has been deleted, false otherwise
 
   const std::string& GetNameForLogs() {return nameForLogs_;}
+
+  virtual bool HasFileExists() = 0;
+  virtual bool FileExists(const std::string& uuid, OrthancPluginContentType type, bool encryptionEnabled) {return false;}
 };
--- a/Common/MoveStorageJob.cpp	Tue Oct 10 15:40:36 2023 +0200
+++ b/Common/MoveStorageJob.cpp	Tue Oct 10 16:11:18 2023 +0200
@@ -67,7 +67,21 @@
   // read from source storage
   try
   {
-    OrthancPlugins::LogInfo("Move attachment: " + sourceStorage->GetNameForLogs() + ": reading attachment " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type));
+    if (sourceStorage->HasFileExists() && !sourceStorage->FileExists(uuid, static_cast<OrthancPluginContentType>(type), cryptoEnabled))
+    {
+      OrthancPlugins::LogInfo("Move attachment: " + sourceStorage->GetNameForLogs() + " " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type) + ", skipping, file is not on the source anymore");
+      return true;
+    }
+    else if (targetStorage->HasFileExists() && targetStorage->FileExists(uuid, static_cast<OrthancPluginContentType>(type), cryptoEnabled))
+    {
+      OrthancPlugins::LogInfo("Move attachment: " + targetStorage->GetNameForLogs() + " " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type) + ", skipping, file already on the target");
+      return true;
+    }
+    else
+    {
+      OrthancPlugins::LogInfo("Move attachment: " + sourceStorage->GetNameForLogs() + ": reading attachment " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type));
+    }
+
     std::unique_ptr<IStorage::IReader> reader(sourceStorage->GetReaderForObject(uuid.c_str(), static_cast<OrthancPluginContentType>(type), cryptoEnabled));
 
     size_t fileSize = reader->GetSize();
@@ -97,7 +111,7 @@
     }
   }
 
-  // everything went well so fare, we can delete from source storage
+  // everything went well so far, we can delete from source storage
   if (buffer.size() > 0)
   {
     try
--- a/Google/GoogleStoragePlugin.cpp	Tue Oct 10 15:40:36 2023 +0200
+++ b/Google/GoogleStoragePlugin.cpp	Tue Oct 10 16:11:18 2023 +0200
@@ -45,6 +45,7 @@
   virtual IWriter* GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled);
   virtual IReader* GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled);
   virtual void DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled);
+  virtual bool HasFileExists() {return false;};
 };
 
 
--- a/NEWS	Tue Oct 10 15:40:36 2023 +0200
+++ b/NEWS	Tue Oct 10 16:11:18 2023 +0200
@@ -9,6 +9,7 @@
     especially for large files.
   * now using the latest AWS SDK C++ (1.11.178).
 
+* in /move-storage: now detecting if file should be moved or not.
 
 2023-07-20 - v 2.2.0
 ====================