annotate OrthancFramework/Sources/FileStorage/FilesystemStorage.cpp @ 5447:dacdce5e5c22

now accepting GET requests on the /tools/create-archive route and siblings
author Alain Mazy <am@osimis.io>
date Fri, 24 Nov 2023 18:14:52 +0100
parents b83192e7ad10
children 48b8dae6dc77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1582
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1250
diff changeset
4 * Department, University Hospital of Liege, Belgium
5185
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
11 * the License, or (at your option) any later version.
136
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 110
diff changeset
12 *
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
16 * Lesser General Public License for more details.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
20 * <http://www.gnu.org/licenses/>.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
24 #include "../PrecompiledHeaders.h"
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
25 #include "FilesystemStorage.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 // http://stackoverflow.com/questions/1576272/storing-large-number-of-files-in-file-system
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 // http://stackoverflow.com/questions/446358/storing-a-large-number-of-images
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1397
diff changeset
30 #include "../Logging.h"
234
7c1faef915a4 cleaning room
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
31 #include "../OrthancException.h"
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
32 #include "../StringMemoryBuffer.h"
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
33 #include "../SystemToolbox.h"
234
7c1faef915a4 cleaning room
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
34 #include "../Toolbox.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include <boost/filesystem/fstream.hpp>
1397
704de8c30ff5 modularization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
37
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
110
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
39 static std::string ToString(const boost::filesystem::path& p)
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
40 {
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
41 #if BOOST_HAS_FILESYSTEM_V3 == 1
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
42 return p.filename().string();
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
43 #else
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
44 return p.filename();
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
45 #endif
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
46 }
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
47
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
48
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
49 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
51 boost::filesystem::path FilesystemStorage::GetPath(const std::string& uuid) const
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 namespace fs = boost::filesystem;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 if (!Toolbox::IsUuid(uuid))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
59
c996319e90bc renaming in Core
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
57 throw OrthancException(ErrorCode_ParameterOutOfRange);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 fs::path path = root_;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 path /= std::string(&uuid[0], &uuid[2]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 path /= std::string(&uuid[2], &uuid[4]);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 path /= uuid;
110
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
65
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
66 #if BOOST_HAS_FILESYSTEM_V3 == 1
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 path.make_preferred();
110
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
68 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 return path;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
4185
b289a1234822 giving a try to cross-platform compilation of SyncStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
73 void FilesystemStorage::Setup(const std::string& root)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
110
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
75 //root_ = boost::filesystem::absolute(root).string();
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
76 root_ = root;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
78 SystemToolbox::MakeDirectory(root);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
4300
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
81 FilesystemStorage::FilesystemStorage(const std::string &root) :
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
82 fsyncOnWrite_(false)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
83 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
84 Setup(root);
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
85 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
86
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
87 FilesystemStorage::FilesystemStorage(const std::string &root,
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
88 bool fsyncOnWrite) :
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
89 fsyncOnWrite_(fsyncOnWrite)
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
90 {
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
91 Setup(root);
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
92 }
b30a8de92ad9 abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4273
diff changeset
93
2087
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
94
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
95
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
96 static const char* GetDescriptionInternal(FileContentType content)
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
97 {
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
98 // This function is for logging only (internal use), a more
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
99 // fully-featured version is available in ServerEnumerations.cpp
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
100 switch (content)
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
101 {
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
102 case FileContentType_Unknown:
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
103 return "Unknown";
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
104
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
105 case FileContentType_Dicom:
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
106 return "DICOM";
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
107
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
108 case FileContentType_DicomAsJson:
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
109 return "JSON summary of DICOM";
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
110
4512
cff7fdfc83a4 added FileContentType_DicomUntilPixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4495
diff changeset
111 case FileContentType_DicomUntilPixelData:
cff7fdfc83a4 added FileContentType_DicomUntilPixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4495
diff changeset
112 return "DICOM until pixel data";
cff7fdfc83a4 added FileContentType_DicomUntilPixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4495
diff changeset
113
2087
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
114 default:
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
115 return "User-defined";
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
116 }
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
117 }
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
118
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
119
1135
67c3c1e4a6e0 index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1126
diff changeset
120 void FilesystemStorage::Create(const std::string& uuid,
67c3c1e4a6e0 index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1126
diff changeset
121 const void* content,
67c3c1e4a6e0 index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1126
diff changeset
122 size_t size,
2087
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
123 FileContentType type)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
5430
b83192e7ad10 Now displaying timings when reading from/writing to disk in the verbose logs
Alain Mazy <am@osimis.io>
parents: 5374
diff changeset
125 Toolbox::ElapsedTimer timer;
b83192e7ad10 Now displaying timings when reading from/writing to disk in the verbose logs
Alain Mazy <am@osimis.io>
parents: 5374
diff changeset
126 LOG(INFO) << "Creating attachment \"" << uuid << "\" of \"" << GetDescriptionInternal(type)
b83192e7ad10 Now displaying timings when reading from/writing to disk in the verbose logs
Alain Mazy <am@osimis.io>
parents: 5374
diff changeset
127 << "\" type";
2087
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
128
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 boost::filesystem::path path;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
1135
67c3c1e4a6e0 index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1126
diff changeset
131 path = GetPath(uuid);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
1135
67c3c1e4a6e0 index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1126
diff changeset
133 if (boost::filesystem::exists(path))
67c3c1e4a6e0 index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1126
diff changeset
134 {
67c3c1e4a6e0 index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1126
diff changeset
135 // Extremely unlikely case: This Uuid has already been created
67c3c1e4a6e0 index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1126
diff changeset
136 // in the past.
67c3c1e4a6e0 index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1126
diff changeset
137 throw OrthancException(ErrorCode_InternalError);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 if (boost::filesystem::exists(path.parent_path()))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 if (!boost::filesystem::is_directory(path.parent_path()))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1487
diff changeset
144 throw OrthancException(ErrorCode_DirectoryOverFile);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 if (!boost::filesystem::create_directories(path.parent_path()))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 {
1582
bd1889029cbb encoding of exceptions
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1487
diff changeset
151 throw OrthancException(ErrorCode_FileStorageCannotWrite);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
4185
b289a1234822 giving a try to cross-platform compilation of SyncStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
155 SystemToolbox::WriteFile(content, size, path.string(), fsyncOnWrite_);
5430
b83192e7ad10 Now displaying timings when reading from/writing to disk in the verbose logs
Alain Mazy <am@osimis.io>
parents: 5374
diff changeset
156 LOG(INFO) << "Created attachment \"" << uuid << "\" (" << timer.GetHumanTransferSpeed(true, size) << ")";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
160 IMemoryBuffer* FilesystemStorage::Read(const std::string& uuid,
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
161 FileContentType type)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
5430
b83192e7ad10 Now displaying timings when reading from/writing to disk in the verbose logs
Alain Mazy <am@osimis.io>
parents: 5374
diff changeset
163 Toolbox::ElapsedTimer timer;
2087
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
164 LOG(INFO) << "Reading attachment \"" << uuid << "\" of \"" << GetDescriptionInternal(type)
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
165 << "\" content type";
e9e6ffbf0fd5 improved logging in FilesystemStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1911
diff changeset
166
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
167 std::string content;
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
168 SystemToolbox::ReadFile(content, GetPath(uuid).string());
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
169
5430
b83192e7ad10 Now displaying timings when reading from/writing to disk in the verbose logs
Alain Mazy <am@osimis.io>
parents: 5374
diff changeset
170 LOG(INFO) << "Read attachment \"" << uuid << "\" (" << timer.GetHumanTransferSpeed(true, content.size()) << ")";
b83192e7ad10 Now displaying timings when reading from/writing to disk in the verbose logs
Alain Mazy <am@osimis.io>
parents: 5374
diff changeset
171
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
172 return StringMemoryBuffer::CreateFromSwap(content);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
4495
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
176 IMemoryBuffer* FilesystemStorage::ReadRange(const std::string& uuid,
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
177 FileContentType type,
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
178 uint64_t start /* inclusive */,
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
179 uint64_t end /* exclusive */)
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
180 {
5430
b83192e7ad10 Now displaying timings when reading from/writing to disk in the verbose logs
Alain Mazy <am@osimis.io>
parents: 5374
diff changeset
181 Toolbox::ElapsedTimer timer;
4495
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
182 LOG(INFO) << "Reading attachment \"" << uuid << "\" of \"" << GetDescriptionInternal(type)
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
183 << "\" content type (range from " << start << " to " << end << ")";
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
184
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
185 std::string content;
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
186 SystemToolbox::ReadFileRange(
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
187 content, GetPath(uuid).string(), start, end, true /* throw if overflow */);
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
188
5430
b83192e7ad10 Now displaying timings when reading from/writing to disk in the verbose logs
Alain Mazy <am@osimis.io>
parents: 5374
diff changeset
189 LOG(INFO) << "Read range of attachment \"" << uuid << "\" (" << timer.GetHumanTransferSpeed(true, content.size()) << ")";
4495
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
190 return StringMemoryBuffer::CreateFromSwap(content);
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
191 }
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
192
fa2311f94d9f IStorageArea::ReadRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
193
4520
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4512
diff changeset
194 bool FilesystemStorage::HasReadRange() const
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4512
diff changeset
195 {
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4512
diff changeset
196 return true;
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4512
diff changeset
197 }
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4512
diff changeset
198
f5cb0c0ffbed added unit test OrthancFramework.SizeOf to dump sizeof all the public classes in the Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4512
diff changeset
199
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
200 uintmax_t FilesystemStorage::GetSize(const std::string& uuid) const
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 boost::filesystem::path path = GetPath(uuid);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 return boost::filesystem::file_size(path);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
208 void FilesystemStorage::ListAllFiles(std::set<std::string>& result) const
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 namespace fs = boost::filesystem;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 result.clear();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 if (fs::exists(root_) && fs::is_directory(root_))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 for (fs::recursive_directory_iterator current(root_), end; current != end ; ++current)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 {
2140
aa4b8895cd23 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2129
diff changeset
218 if (SystemToolbox::IsRegularFile(current->path().string()))
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 try
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 fs::path d = current->path();
110
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
223 std::string uuid = ToString(d);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 if (Toolbox::IsUuid(uuid))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 fs::path p0 = d.parent_path().parent_path().parent_path();
110
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
227 std::string p1 = ToString(d.parent_path().parent_path());
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
228 std::string p2 = ToString(d.parent_path());
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 if (p1.length() == 2 &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 p2.length() == 2 &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 p1 == uuid.substr(0, 2) &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 p2 == uuid.substr(2, 2) &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 p0 == root_)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 result.insert(uuid);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 }
2836
7133ad478eea fix Debian warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
239 catch (fs::filesystem_error&)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
248 void FilesystemStorage::Clear()
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 namespace fs = boost::filesystem;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 typedef std::set<std::string> List;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 List result;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 ListAllFiles(result);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255
656
08eca5d86aad fixes to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
256 for (List::const_iterator it = result.begin(); it != result.end(); ++it)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 {
1126
bf67431a7383 handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1124
diff changeset
258 Remove(*it, FileContentType_Unknown /*ignored in this class*/);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262
1126
bf67431a7383 handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1124
diff changeset
263 void FilesystemStorage::Remove(const std::string& uuid,
2129
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2087
diff changeset
264 FileContentType type)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 {
2129
0c09d1af22f3 "/tools/invalidate-tags" to invalidate the JSON summary of all the DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2087
diff changeset
266 LOG(INFO) << "Deleting attachment \"" << uuid << "\" of type " << static_cast<int>(type);
1397
704de8c30ff5 modularization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
267
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 namespace fs = boost::filesystem;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 fs::path p = GetPath(uuid);
147
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 142
diff changeset
271
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 142
diff changeset
272 try
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 142
diff changeset
273 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 142
diff changeset
274 fs::remove(p);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 142
diff changeset
275 }
148
jodogne
parents: 147
diff changeset
276 catch (...)
147
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 142
diff changeset
277 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 142
diff changeset
278 // Ignore the error
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 142
diff changeset
279 }
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 // Remove the two parent directories, ignoring the error code if
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 // these directories are not empty
110
fd7b0a3e6260 support of boost 1.42 for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 59
diff changeset
283
142
jodogne
parents: 136
diff changeset
284 try
jodogne
parents: 136
diff changeset
285 {
147
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 142
diff changeset
286 #if BOOST_HAS_FILESYSTEM_V3 == 1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 142
diff changeset
287 boost::system::error_code err;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 142
diff changeset
288 fs::remove(p.parent_path(), err);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 142
diff changeset
289 fs::remove(p.parent_path().parent_path(), err);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 142
diff changeset
290 #else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 142
diff changeset
291 fs::remove(p.parent_path());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 142
diff changeset
292 fs::remove(p.parent_path().parent_path());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 142
diff changeset
293 #endif
142
jodogne
parents: 136
diff changeset
294 }
148
jodogne
parents: 147
diff changeset
295 catch (...)
142
jodogne
parents: 136
diff changeset
296 {
jodogne
parents: 136
diff changeset
297 // Ignore the error
jodogne
parents: 136
diff changeset
298 }
jodogne
parents: 136
diff changeset
299 }
jodogne
parents: 136
diff changeset
300
jodogne
parents: 136
diff changeset
301
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
302 uintmax_t FilesystemStorage::GetCapacity() const
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 return boost::filesystem::space(root_).capacity;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
307 uintmax_t FilesystemStorage::GetAvailableSpace() const
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 return boost::filesystem::space(root_).available;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 }
4273
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4185
diff changeset
311
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4185
diff changeset
312
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4185
diff changeset
313 #if ORTHANC_BUILDING_FRAMEWORK_LIBRARY == 1
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4185
diff changeset
314 FilesystemStorage::FilesystemStorage(std::string root) :
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4185
diff changeset
315 fsyncOnWrite_(false)
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4185
diff changeset
316 {
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4185
diff changeset
317 Setup(root);
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4185
diff changeset
318 }
0034f855c023 tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4185
diff changeset
319 #endif
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
320
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
321
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
322 #if ORTHANC_BUILDING_FRAMEWORK_LIBRARY == 1
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
323 void FilesystemStorage::Read(std::string& content,
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
324 const std::string& uuid,
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
325 FileContentType type)
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
326 {
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
327 std::unique_ptr<IMemoryBuffer> buffer(Read(uuid, type));
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
328 buffer->MoveToString(content);
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
329 }
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
330 #endif
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 }