Mercurial > hg > orthanc-object-storage
changeset 64:c4f56973a279
Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 09 Jul 2021 13:03:24 +0200 |
parents | 5d2e9399bdd8 |
children | b1df69fcc871 |
files | Aws/AwsS3StoragePlugin.cpp Common/BaseStoragePlugin.cpp Common/BaseStoragePlugin.h NEWS |
diffstat | 4 files changed, 60 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/Aws/AwsS3StoragePlugin.cpp Tue Jul 06 17:24:15 2021 +0200 +++ b/Aws/AwsS3StoragePlugin.cpp Fri Jul 09 13:03:24 2021 +0200 @@ -100,15 +100,17 @@ class Reader : public IStoragePlugin::IReader { - std::string path_; Aws::S3::S3Client client_; std::string bucketName_; + std::list<std::string> paths_; + std::string uuid_; public: - Reader(const Aws::S3::S3Client& client, const std::string& bucketName, const std::string& path) - : path_(path), - client_(client), - bucketName_(bucketName) + Reader(const Aws::S3::S3Client& client, const std::string& bucketName, const std::list<std::string>& paths, const char* uuid) + : client_(client), + bucketName_(bucketName), + paths_(paths), + uuid_(uuid) { } @@ -116,11 +118,12 @@ { } - virtual size_t GetSize() + + size_t _GetSize(const std::string& path) { Aws::S3::Model::ListObjectsRequest listObjectRequest; listObjectRequest.SetBucket(bucketName_.c_str()); - listObjectRequest.SetPrefix(path_.c_str()); + listObjectRequest.SetPrefix(path.c_str()); auto result = client_.ListObjects(listObjectRequest); @@ -135,16 +138,32 @@ } else if (objectList.size() > 1) { - throw StoragePluginException(std::string("error while reading file ") + path_ + ": multiple objet with same name !"); + throw StoragePluginException(std::string("error while reading file ") + path + ": multiple objet with same name !"); } - throw StoragePluginException(std::string("error while reading file ") + path_ + ": object not found !"); + throw StoragePluginException(std::string("error while reading file ") + path + ": object not found !"); } else { - throw StoragePluginException(std::string("error while reading file ") + path_ + ": " + result.GetError().GetExceptionName().c_str() + " " + result.GetError().GetMessage().c_str()); + throw StoragePluginException(std::string("error while reading file ") + path + ": " + result.GetError().GetExceptionName().c_str() + " " + result.GetError().GetMessage().c_str()); } } + virtual size_t GetSize() + { + for (auto& path: paths_) + { + try + { + return _GetSize(path); + } + catch (StoragePluginException&) + { + //ignore to retry + } + } + throw StoragePluginException(std::string("error while trying to get file size with uuid " + uuid_)); + } + virtual void ReadWhole(char* data, size_t size) { _Read(data, size, 0, false); @@ -157,9 +176,25 @@ void _Read(char* data, size_t size, size_t fromOffset, bool useRange) { + for (auto& path: paths_) + { + try + { + return __Read(path, data, size, fromOffset, useRange); + } + catch (StoragePluginException&) + { + //ignore to retry + } + } + throw StoragePluginException(std::string("error while trying to read file with uuid " + uuid_)); + } + + void __Read(const std::string& path, char* data, size_t size, size_t fromOffset, bool useRange) + { Aws::S3::Model::GetObjectRequest getObjectRequest; getObjectRequest.SetBucket(bucketName_.c_str()); - getObjectRequest.SetKey(path_.c_str()); + getObjectRequest.SetKey(path.c_str()); if (useRange) { @@ -187,7 +222,7 @@ } else { - throw StoragePluginException(std::string("error while reading file ") + path_ + ": " + result.GetError().GetExceptionName().c_str() + " " + result.GetError().GetMessage().c_str()); + throw StoragePluginException(std::string("error while reading file ") + path + ": " + result.GetError().GetExceptionName().c_str() + " " + result.GetError().GetMessage().c_str()); } } @@ -328,7 +363,6 @@ client_(client), bucketName_(bucketName) { - } IStoragePlugin::IWriter* AwsS3StoragePlugin::GetWriterForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) @@ -338,7 +372,11 @@ IStoragePlugin::IReader* AwsS3StoragePlugin::GetReaderForObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) { - return new Reader(client_, bucketName_, GetPath(uuid, type, encryptionEnabled)); + std::list<std::string> paths; + paths.push_back(GetPath(uuid, type, encryptionEnabled, false)); + paths.push_back(GetPath(uuid, type, encryptionEnabled, true)); + + return new Reader(client_, bucketName_, paths, uuid); } void AwsS3StoragePlugin::DeleteObject(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled)
--- a/Common/BaseStoragePlugin.cpp Tue Jul 06 17:24:15 2021 +0200 +++ b/Common/BaseStoragePlugin.cpp Fri Jul 09 13:03:24 2021 +0200 @@ -34,7 +34,7 @@ } -std::string BaseStoragePlugin::GetPath(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled) +std::string BaseStoragePlugin::GetPath(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled, bool useAlternateExtension) { if (enableLegacyStorageStructure_) { @@ -53,7 +53,7 @@ { filename += ".json"; } - else if (type == OrthancPluginContentType_DicomUntilPixelData) + else if (type == OrthancPluginContentType_DicomUntilPixelData && !useAlternateExtension) // for some time, header files were saved with .unk (happened with S3 storage plugin between version 1.2.0 and 1.3.0 - 21.5.1 and 21.6.2) { filename += ".dcm.head"; }
--- a/Common/BaseStoragePlugin.h Tue Jul 06 17:24:15 2021 +0200 +++ b/Common/BaseStoragePlugin.h Fri Jul 09 13:03:24 2021 +0200 @@ -32,7 +32,7 @@ enableLegacyStorageStructure_(enableLegacyStorageStructure) {} - std::string GetPath(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled); + std::string GetPath(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled, bool useAlternateExtension = false); public: virtual void SetRootPath(const std::string& rootPath)
--- a/NEWS Tue Jul 06 17:24:15 2021 +0200 +++ b/NEWS Fri Jul 09 13:03:24 2021 +0200 @@ -1,3 +1,8 @@ +Pending changes in the mainline +=============================== + +* Fix reading/deleting DCM header files that were saved with plugin v 1.2.0 and Orthanc 1.9.3 which had a .unk extension. + 2021-06-29 - v 1.3.0 ====================