Mercurial > hg > orthanc-object-storage
comparison Common/MoveStorageJob.cpp @ 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 | 8a9207933297 |
children | 3c7e0374f28e |
comparison
equal
deleted
inserted
replaced
110:37a4b8e2577f | 111:407bd022b0cf |
---|---|
65 std::vector<char> buffer; | 65 std::vector<char> buffer; |
66 | 66 |
67 // read from source storage | 67 // read from source storage |
68 try | 68 try |
69 { | 69 { |
70 OrthancPlugins::LogInfo("Move attachment: " + sourceStorage->GetNameForLogs() + ": reading attachment " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type)); | 70 if (sourceStorage->HasFileExists() && !sourceStorage->FileExists(uuid, static_cast<OrthancPluginContentType>(type), cryptoEnabled)) |
71 { | |
72 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"); | |
73 return true; | |
74 } | |
75 else if (targetStorage->HasFileExists() && targetStorage->FileExists(uuid, static_cast<OrthancPluginContentType>(type), cryptoEnabled)) | |
76 { | |
77 OrthancPlugins::LogInfo("Move attachment: " + targetStorage->GetNameForLogs() + " " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type) + ", skipping, file already on the target"); | |
78 return true; | |
79 } | |
80 else | |
81 { | |
82 OrthancPlugins::LogInfo("Move attachment: " + sourceStorage->GetNameForLogs() + ": reading attachment " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type)); | |
83 } | |
84 | |
71 std::unique_ptr<IStorage::IReader> reader(sourceStorage->GetReaderForObject(uuid.c_str(), static_cast<OrthancPluginContentType>(type), cryptoEnabled)); | 85 std::unique_ptr<IStorage::IReader> reader(sourceStorage->GetReaderForObject(uuid.c_str(), static_cast<OrthancPluginContentType>(type), cryptoEnabled)); |
72 | 86 |
73 size_t fileSize = reader->GetSize(); | 87 size_t fileSize = reader->GetSize(); |
74 buffer.resize(fileSize); | 88 buffer.resize(fileSize); |
75 | 89 |
95 OrthancPlugins::LogError("Move attachment: " + targetStorage->GetNameForLogs() + ": error while writing attachment " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type) + ": " + ex.what()); | 109 OrthancPlugins::LogError("Move attachment: " + targetStorage->GetNameForLogs() + ": error while writing attachment " + std::string(uuid) + " of type " + boost::lexical_cast<std::string>(type) + ": " + ex.what()); |
96 return false; | 110 return false; |
97 } | 111 } |
98 } | 112 } |
99 | 113 |
100 // everything went well so fare, we can delete from source storage | 114 // everything went well so far, we can delete from source storage |
101 if (buffer.size() > 0) | 115 if (buffer.size() > 0) |
102 { | 116 { |
103 try | 117 try |
104 { | 118 { |
105 sourceStorage->DeleteObject(uuid.c_str(), static_cast<OrthancPluginContentType>(type), cryptoEnabled); | 119 sourceStorage->DeleteObject(uuid.c_str(), static_cast<OrthancPluginContentType>(type), cryptoEnabled); |