annotate OrthancFramework/Sources/HttpServer/WebDavStorage.cpp @ 4671:42e1f5bde40b

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