annotate OrthancFramework/Sources/HttpServer/WebDavStorage.cpp @ 5317:9875e1f24394

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