annotate Common/BaseStorage.cpp @ 210:408c90c9027f default tip

todo: google soft delete
author Alain Mazy <am@orthanc.team>
date Wed, 09 Oct 2024 11:48:14 +0200
parents d62f52be1943
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
56
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
1 /**
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
2 * Cloud storage plugins for Orthanc
145
3c7e0374f28e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 78
diff changeset
3 * Copyright (C) 2020-2023 Osimis S.A., Belgium
3c7e0374f28e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 78
diff changeset
4 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
3c7e0374f28e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 78
diff changeset
5 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
56
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
6 *
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
7 * This program is free software: you can redistribute it and/or
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
10 * the License, or (at your option) any later version.
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
11 *
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
12 * This program is distributed in the hope that it will be useful, but
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
15 * Affero General Public License for more details.
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
16 *
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
19 **/
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
20
b922ae86bbe1 full static linking against AWS SDK
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
21
78
d7295e8678d7 renames
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
22 #include "BaseStorage.h"
152
d62f52be1943 use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 145
diff changeset
23
d62f52be1943 use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 145
diff changeset
24 #include <Logging.h>
d62f52be1943 use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 145
diff changeset
25
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
26 #include <boost/filesystem/fstream.hpp>
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
27
78
d7295e8678d7 renames
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
28 boost::filesystem::path BaseStorage::GetOrthancFileSystemPath(const std::string& uuid, const std::string& fileSystemRootPath)
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
29 {
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
30 boost::filesystem::path path = fileSystemRootPath;
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
31
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
32 path /= std::string(&uuid[0], &uuid[2]);
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
33 path /= std::string(&uuid[2], &uuid[4]);
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
34 path /= uuid;
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
35
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
36 path.make_preferred();
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
37
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 70
diff changeset
38 return path;
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
39 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
40
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
41
78
d7295e8678d7 renames
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
42 std::string BaseStorage::GetPath(const char* uuid, OrthancPluginContentType type, bool encryptionEnabled, bool useAlternateExtension)
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
43 {
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
44 if (enableLegacyStorageStructure_)
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
45 {
77
80792bb9600e new HybridMode
Alain Mazy <am@osimis.io>
parents: 70
diff changeset
46 return GetOrthancFileSystemPath(uuid, rootPath_).string();
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
47 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
48 else
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
49 {
20
968eb1c78aed Added 'RootPath' configuration
Alain Mazy
parents: 15
diff changeset
50 boost::filesystem::path path = rootPath_;
968eb1c78aed Added 'RootPath' configuration
Alain Mazy
parents: 15
diff changeset
51 std::string filename = std::string(uuid);
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
52
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
53 if (type == OrthancPluginContentType_Dicom)
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
54 {
20
968eb1c78aed Added 'RootPath' configuration
Alain Mazy
parents: 15
diff changeset
55 filename += ".dcm";
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
56 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
57 else if (type == OrthancPluginContentType_DicomAsJson)
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
58 {
20
968eb1c78aed Added 'RootPath' configuration
Alain Mazy
parents: 15
diff changeset
59 filename += ".json";
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
60 }
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
Alain Mazy <am@osimis.io>
parents: 56
diff changeset
61 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)
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 20
diff changeset
62 {
55
9d03e24dafc1 fix extension of DCM header files
Alain Mazy <am@osimis.io>
parents: 49
diff changeset
63 filename += ".dcm.head";
39
50d0be413c42 implemented ReadRange (only in Azure plugin right now)
Alain Mazy <am@osimis.io>
parents: 20
diff changeset
64 }
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
65 else
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
66 {
20
968eb1c78aed Added 'RootPath' configuration
Alain Mazy
parents: 15
diff changeset
67 filename += ".unk";
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
68 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
69
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
70 if (encryptionEnabled)
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
71 {
20
968eb1c78aed Added 'RootPath' configuration
Alain Mazy
parents: 15
diff changeset
72 filename += ".enc";
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
73 }
20
968eb1c78aed Added 'RootPath' configuration
Alain Mazy
parents: 15
diff changeset
74 path /= filename;
968eb1c78aed Added 'RootPath' configuration
Alain Mazy
parents: 15
diff changeset
75
968eb1c78aed Added 'RootPath' configuration
Alain Mazy
parents: 15
diff changeset
76 return path.string();
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
77 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
78 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
79
78
d7295e8678d7 renames
Alain Mazy <am@osimis.io>
parents: 77
diff changeset
80 bool BaseStorage::ReadCommonConfiguration(bool& enableLegacyStorageStructure, bool& storageContainsUnknownFiles, const OrthancPlugins::OrthancConfiguration& pluginSection)
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
81 {
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
82 std::string storageStructure = pluginSection.GetStringValue("StorageStructure", "flat");
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
83 if (storageStructure == "flat")
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
84 {
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
85 enableLegacyStorageStructure = false;
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
86 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
87 else
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
88 {
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
89 enableLegacyStorageStructure = true;
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
90 if (storageStructure != "legacy")
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
91 {
152
d62f52be1943 use Orthanc frameworking for logging
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 145
diff changeset
92 LOG(ERROR) << "ObjectStorage/StorageStructure configuration invalid value: " << storageStructure << ", allowed values are 'flat' and 'legacy'";
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
93 return false;
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
94 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
95 }
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
96
70
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 64
diff changeset
97 storageContainsUnknownFiles = pluginSection.GetBooleanValue("EnableLegacyUnknownFiles", false);
16e419fe80c5 Google & Azure: Added the "EnableLegacyUnknownFiles" configuration option
Alain Mazy <am@osimis.io>
parents: 64
diff changeset
98
15
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
99 return true;
2a02b21f0a19 migration + storage structure
Alain Mazy
parents:
diff changeset
100 }