annotate OrthancFramework/Sources/HttpServer/WebDavStorage.cpp @ 5765:247fc5368693 find-refactoring

un-sharing DatabaseConstraint and ISqlLookupFormatter with orthanc-databases
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 09 Sep 2024 16:14:22 +0200
parents f7adfb22e20e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4230
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
4230
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * modify it under the terms of the GNU Lesser General Public License
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * as published by the Free Software Foundation, either version 3 of
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * the License, or (at your option) any later version.
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * Lesser General Public License for more details.
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * License along with this program. If not, see
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * <http://www.gnu.org/licenses/>.
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 **/
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "../PrecompiledHeaders.h"
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "WebDavStorage.h"
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
4304
50b0c69b653a continued abi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4239
diff changeset
28 #include "../Logging.h"
4230
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "../OrthancException.h"
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "../SystemToolbox.h"
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include "../TemporaryFile.h"
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include "../Toolbox.h"
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 namespace Orthanc
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 class WebDavStorage::StorageFile : public boost::noncopyable
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 private:
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 std::unique_ptr<TemporaryFile> file_;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 std::string content_;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 MimeType mime_;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 boost::posix_time::ptime time_;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 void Touch()
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 time_ = boost::posix_time::second_clock::universal_time();
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 public:
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 StorageFile() :
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 mime_(MimeType_Binary)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 Touch();
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 void SetContent(const std::string& content,
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 MimeType mime,
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 bool isMemory)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 if (isMemory)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 content_ = content;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 file_.reset();
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 else
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 content_.clear();
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 file_.reset(new TemporaryFile);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 file_->Write(content);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 mime_ = mime;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 Touch();
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 MimeType GetMimeType() const
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 return mime_;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 void GetContent(std::string& target) const
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 if (file_.get() == NULL)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 target = content_;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 else
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 file_->Read(target);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 const boost::posix_time::ptime& GetTime() const
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 return time_;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 uint64_t GetContentLength() const
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 if (file_.get() == NULL)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 return content_.size();
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 else
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 return file_->GetFileSize();
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 };
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 class WebDavStorage::StorageFolder : public boost::noncopyable
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 private:
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 typedef std::map<std::string, StorageFile*> Files;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 typedef std::map<std::string, StorageFolder*> Subfolders;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
4233
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
118 Files files_;
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
119 Subfolders subfolders_;
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
120 boost::posix_time::ptime time_;
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
121
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
122 void Touch()
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
123 {
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
124 time_ = boost::posix_time::second_clock::universal_time();
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
125 }
4230
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 void CheckName(const std::string& name)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 if (name.empty() ||
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 name.find('/') != std::string::npos ||
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 name.find('\\') != std::string::npos ||
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 name.find('\0') != std::string::npos)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 throw OrthancException(ErrorCode_ParameterOutOfRange,
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 "Bad resource name for WebDAV: " + name);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 bool IsExisting(const std::string& name) const
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 return (files_.find(name) != files_.end() ||
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 subfolders_.find(name) != subfolders_.end());
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 public:
4233
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
146 StorageFolder()
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
147 {
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
148 Touch();
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
149 }
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
150
4230
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 ~StorageFolder()
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 for (Files::iterator it = files_.begin(); it != files_.end(); ++it)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 assert(it->second != NULL);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 delete it->second;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 for (Subfolders::iterator it = subfolders_.begin(); it != subfolders_.end(); ++it)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 assert(it->second != NULL);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 delete it->second;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
4239
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
166 size_t GetSize() const
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
167 {
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
168 return files_.size() + subfolders_.size();
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
169 }
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
170
4233
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
171 const boost::posix_time::ptime& GetModificationTime() const
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
172 {
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
173 return time_;
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
174 }
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
175
4230
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 const StorageFile* LookupFile(const std::string& name) const
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 Files::const_iterator found = files_.find(name);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 if (found == files_.end())
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 return NULL;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 else
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 assert(found->second != NULL);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 return found->second;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 bool CreateSubfolder(const std::string& name)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 CheckName(name);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 if (IsExisting(name))
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 LOG(ERROR) << "WebDAV folder already existing: " << name;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 return false;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 else
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 subfolders_[name] = new StorageFolder;
4233
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
202 Touch();
4230
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 return true;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 bool StoreFile(const std::string& name,
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 const std::string& content,
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 MimeType mime,
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 bool isMemory)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 CheckName(name);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 if (subfolders_.find(name) != subfolders_.end())
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 LOG(ERROR) << "WebDAV folder already existing: " << name;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 return false;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 Files::iterator found = files_.find(name);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 if (found == files_.end())
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 std::unique_ptr<StorageFile> f(new StorageFile);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 f->SetContent(content, mime, isMemory);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 files_[name] = f.release();
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 else
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 assert(found->second != NULL);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 found->second->SetContent(content, mime, isMemory);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
4233
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
233 Touch();
4230
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 return true;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 StorageFolder* LookupFolder(const std::vector<std::string>& path)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 if (path.empty())
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 return this;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 else
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 Subfolders::const_iterator found = subfolders_.find(path[0]);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 if (found == subfolders_.end())
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 return NULL;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 else
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 assert(found->second != NULL);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 std::vector<std::string> p(path.begin() + 1, path.end());
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 return found->second->LookupFolder(p);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 void ListCollection(Collection& collection) const
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 for (Files::const_iterator it = files_.begin(); it != files_.end(); ++it)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 assert(it->second != NULL);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 std::unique_ptr<File> f(new File(it->first));
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 f->SetContentLength(it->second->GetContentLength());
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 f->SetCreationTime(it->second->GetTime());
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 collection.AddResource(f.release());
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 for (Subfolders::const_iterator it = subfolders_.begin(); it != subfolders_.end(); ++it)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 {
4233
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
274 std::unique_ptr<Folder> f(new Folder(it->first));
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
275 f->SetModificationTime(it->second->GetModificationTime());
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
276 collection.AddResource(f.release());
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
277 }
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
278 }
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
279
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
280 bool DeleteItem(const std::vector<std::string>& path)
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
281 {
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
282 if (path.size() == 0)
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
283 {
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
284 throw OrthancException(ErrorCode_InternalError);
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
285 }
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
286 else if (path.size() == 1)
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
287 {
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
288 {
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
289 Files::iterator f = files_.find(path[0]);
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
290 if (f != files_.end())
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
291 {
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
292 assert(f->second != NULL);
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
293 delete f->second;
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
294 files_.erase(f);
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
295 Touch();
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
296 return true;
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
297 }
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
298 }
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
299
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
300 {
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
301 Subfolders::iterator f = subfolders_.find(path[0]);
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
302 if (f != subfolders_.end())
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
303 {
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
304 assert(f->second != NULL);
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
305 delete f->second;
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
306 subfolders_.erase(f);
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
307 Touch();
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
308 return true;
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
309 }
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
310 }
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
311
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
312 return false;
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
313 }
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
314 else
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
315 {
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
316 Subfolders::iterator f = subfolders_.find(path[0]);
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
317 if (f != subfolders_.end())
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
318 {
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
319 assert(f->second != NULL);
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
320
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
321 std::vector<std::string> p(path.begin() + 1, path.end());
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
322 if (f->second->DeleteItem(p))
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
323 {
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
324 Touch();
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
325 return true;
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
326 }
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
327 else
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
328 {
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
329 return false;
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
330 }
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
331 }
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
332 else
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
333 {
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
334 return false;
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
335 }
4230
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 }
4239
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
338
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
339
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
340 void RemoveEmptyFolders()
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
341 {
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
342 std::list<std::string> emptyFolders;
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
343
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
344 for (Subfolders::const_iterator it = subfolders_.begin(); it != subfolders_.end(); ++it)
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
345 {
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
346 assert(it->second != NULL);
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
347 it->second->RemoveEmptyFolders();
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
348
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
349 if (it->second->GetSize() == 0)
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
350 {
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
351 assert(it->second != NULL);
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
352 delete it->second;
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
353
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
354 emptyFolders.push_back(it->first);
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
355 }
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
356 }
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
357
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
358 for (std::list<std::string>::const_iterator it = emptyFolders.begin();
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
359 it != emptyFolders.end(); ++it)
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
360 {
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
361 assert(subfolders_.find(*it) != subfolders_.end());
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
362 subfolders_.erase(*it);
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
363 }
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
364 }
4230
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 };
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 WebDavStorage::StorageFolder* WebDavStorage::LookupParentFolder(const std::vector<std::string>& path)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 if (path.empty())
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 throw OrthancException(ErrorCode_ParameterOutOfRange);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 std::vector<std::string> p(path.begin(), path.end() - 1);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 return root_->LookupFolder(p);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 WebDavStorage::WebDavStorage(bool isMemory) :
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 root_(new StorageFolder),
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 isMemory_(isMemory)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 bool WebDavStorage::IsExistingFolder(const std::vector<std::string>& path)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 boost::recursive_mutex::scoped_lock lock(mutex_);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 return (root_->LookupFolder(path) != NULL);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 bool WebDavStorage::ListCollection(Collection& collection,
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 const std::vector<std::string>& path)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 boost::recursive_mutex::scoped_lock lock(mutex_);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 const StorageFolder* folder = root_->LookupFolder(path);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 if (folder == NULL)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 return false;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 else
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 folder->ListCollection(collection);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 return true;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 bool WebDavStorage::GetFileContent(MimeType& mime,
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 std::string& content,
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 boost::posix_time::ptime& modificationTime,
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 const std::vector<std::string>& path)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 boost::recursive_mutex::scoped_lock lock(mutex_);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 const StorageFolder* folder = LookupParentFolder(path);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 if (folder == NULL)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 return false;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 else
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 const StorageFile* file = folder->LookupFile(path.back());
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 if (file == NULL)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 return false;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 else
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 mime = file->GetMimeType();
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 file->GetContent(content);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 modificationTime = file->GetTime();
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 return true;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 bool WebDavStorage::StoreFile(const std::string& content,
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 const std::vector<std::string>& path)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 boost::recursive_mutex::scoped_lock lock(mutex_);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 StorageFolder* folder = LookupParentFolder(path);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 if (folder == NULL)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 LOG(WARNING) << "Inexisting folder in WebDAV: " << Toolbox::FlattenUri(path);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 return false;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 else
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 LOG(INFO) << "Storing " << content.size()
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 << " bytes in WebDAV bucket: " << Toolbox::FlattenUri(path);;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 MimeType mime = SystemToolbox::AutodetectMimeType(path.back());
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 return folder->StoreFile(path.back(), content, mime, isMemory_);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 bool WebDavStorage::CreateFolder(const std::vector<std::string>& path)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 boost::recursive_mutex::scoped_lock lock(mutex_);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 StorageFolder* folder = LookupParentFolder(path);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 if (folder == NULL)
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 LOG(WARNING) << "Inexisting folder in WebDAV: " << Toolbox::FlattenUri(path);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 return false;
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 else
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 {
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 LOG(INFO) << "Creating folder in WebDAV bucket: " << Toolbox::FlattenUri(path);
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 return folder->CreateSubfolder(path.back());
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 }
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 }
4232
688435755466 added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4230
diff changeset
481
688435755466 added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4230
diff changeset
482
688435755466 added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4230
diff changeset
483 bool WebDavStorage::DeleteItem(const std::vector<std::string>& path)
688435755466 added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4230
diff changeset
484 {
4233
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
485 if (path.empty())
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
486 {
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
487 return false; // Cannot delete the root
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
488 }
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
489 else
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
490 {
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
491 boost::recursive_mutex::scoped_lock lock(mutex_);
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
492
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
493 LOG(INFO) << "Deleting from WebDAV bucket: " << Toolbox::FlattenUri(path);
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
494 return root_->DeleteItem(path);
ca2a55a62c81 implementation of DELETE in class WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4232
diff changeset
495 }
4232
688435755466 added DELETE in WebDAV, first working virtual filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4230
diff changeset
496 }
4239
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
497
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
498
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
499 void WebDavStorage::RemoveEmptyFolders()
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
500 {
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
501 boost::recursive_mutex::scoped_lock lock(mutex_);
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
502 root_->RemoveEmptyFolders();
c8754c4c1862 upload DICOM using WebDAV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4233
diff changeset
503 }
4230
b313a0001893 WebDavStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 }