Mercurial > hg > orthanc
comparison OrthancFramework/Sources/HttpServer/WebDavStorage.cpp @ 4233:ca2a55a62c81
implementation of DELETE in class WebDavStorage
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 07 Oct 2020 13:19:53 +0200 |
parents | 688435755466 |
children | c8754c4c1862 |
comparison
equal
deleted
inserted
replaced
4232:688435755466 | 4233:ca2a55a62c81 |
---|---|
110 { | 110 { |
111 private: | 111 private: |
112 typedef std::map<std::string, StorageFile*> Files; | 112 typedef std::map<std::string, StorageFile*> Files; |
113 typedef std::map<std::string, StorageFolder*> Subfolders; | 113 typedef std::map<std::string, StorageFolder*> Subfolders; |
114 | 114 |
115 Files files_; | 115 Files files_; |
116 Subfolders subfolders_; | 116 Subfolders subfolders_; |
117 boost::posix_time::ptime time_; | |
118 | |
119 void Touch() | |
120 { | |
121 time_ = boost::posix_time::second_clock::universal_time(); | |
122 } | |
117 | 123 |
118 void CheckName(const std::string& name) | 124 void CheckName(const std::string& name) |
119 { | 125 { |
120 if (name.empty() || | 126 if (name.empty() || |
121 name.find('/') != std::string::npos || | 127 name.find('/') != std::string::npos || |
132 return (files_.find(name) != files_.end() || | 138 return (files_.find(name) != files_.end() || |
133 subfolders_.find(name) != subfolders_.end()); | 139 subfolders_.find(name) != subfolders_.end()); |
134 } | 140 } |
135 | 141 |
136 public: | 142 public: |
143 StorageFolder() | |
144 { | |
145 Touch(); | |
146 } | |
147 | |
137 ~StorageFolder() | 148 ~StorageFolder() |
138 { | 149 { |
139 for (Files::iterator it = files_.begin(); it != files_.end(); ++it) | 150 for (Files::iterator it = files_.begin(); it != files_.end(); ++it) |
140 { | 151 { |
141 assert(it->second != NULL); | 152 assert(it->second != NULL); |
147 assert(it->second != NULL); | 158 assert(it->second != NULL); |
148 delete it->second; | 159 delete it->second; |
149 } | 160 } |
150 } | 161 } |
151 | 162 |
163 const boost::posix_time::ptime& GetModificationTime() const | |
164 { | |
165 return time_; | |
166 } | |
167 | |
152 const StorageFile* LookupFile(const std::string& name) const | 168 const StorageFile* LookupFile(const std::string& name) const |
153 { | 169 { |
154 Files::const_iterator found = files_.find(name); | 170 Files::const_iterator found = files_.find(name); |
155 if (found == files_.end()) | 171 if (found == files_.end()) |
156 { | 172 { |
173 return false; | 189 return false; |
174 } | 190 } |
175 else | 191 else |
176 { | 192 { |
177 subfolders_[name] = new StorageFolder; | 193 subfolders_[name] = new StorageFolder; |
194 Touch(); | |
178 return true; | 195 return true; |
179 } | 196 } |
180 } | 197 } |
181 | 198 |
182 bool StoreFile(const std::string& name, | 199 bool StoreFile(const std::string& name, |
203 { | 220 { |
204 assert(found->second != NULL); | 221 assert(found->second != NULL); |
205 found->second->SetContent(content, mime, isMemory); | 222 found->second->SetContent(content, mime, isMemory); |
206 } | 223 } |
207 | 224 |
225 Touch(); | |
208 return true; | 226 return true; |
209 } | 227 } |
210 | 228 |
211 StorageFolder* LookupFolder(const std::vector<std::string>& path) | 229 StorageFolder* LookupFolder(const std::vector<std::string>& path) |
212 { | 230 { |
243 collection.AddResource(f.release()); | 261 collection.AddResource(f.release()); |
244 } | 262 } |
245 | 263 |
246 for (Subfolders::const_iterator it = subfolders_.begin(); it != subfolders_.end(); ++it) | 264 for (Subfolders::const_iterator it = subfolders_.begin(); it != subfolders_.end(); ++it) |
247 { | 265 { |
248 collection.AddResource(new Folder(it->first)); | 266 std::unique_ptr<Folder> f(new Folder(it->first)); |
267 f->SetModificationTime(it->second->GetModificationTime()); | |
268 collection.AddResource(f.release()); | |
269 } | |
270 } | |
271 | |
272 bool DeleteItem(const std::vector<std::string>& path) | |
273 { | |
274 if (path.size() == 0) | |
275 { | |
276 throw OrthancException(ErrorCode_InternalError); | |
277 } | |
278 else if (path.size() == 1) | |
279 { | |
280 { | |
281 Files::iterator f = files_.find(path[0]); | |
282 if (f != files_.end()) | |
283 { | |
284 assert(f->second != NULL); | |
285 delete f->second; | |
286 files_.erase(f); | |
287 Touch(); | |
288 return true; | |
289 } | |
290 } | |
291 | |
292 { | |
293 Subfolders::iterator f = subfolders_.find(path[0]); | |
294 if (f != subfolders_.end()) | |
295 { | |
296 assert(f->second != NULL); | |
297 delete f->second; | |
298 subfolders_.erase(f); | |
299 Touch(); | |
300 return true; | |
301 } | |
302 } | |
303 | |
304 return false; | |
305 } | |
306 else | |
307 { | |
308 Subfolders::iterator f = subfolders_.find(path[0]); | |
309 if (f != subfolders_.end()) | |
310 { | |
311 assert(f->second != NULL); | |
312 | |
313 std::vector<std::string> p(path.begin() + 1, path.end()); | |
314 if (f->second->DeleteItem(p)) | |
315 { | |
316 Touch(); | |
317 return true; | |
318 } | |
319 else | |
320 { | |
321 return false; | |
322 } | |
323 } | |
324 else | |
325 { | |
326 return false; | |
327 } | |
249 } | 328 } |
250 } | 329 } |
251 }; | 330 }; |
252 | 331 |
253 | 332 |
366 } | 445 } |
367 | 446 |
368 | 447 |
369 bool WebDavStorage::DeleteItem(const std::vector<std::string>& path) | 448 bool WebDavStorage::DeleteItem(const std::vector<std::string>& path) |
370 { | 449 { |
371 // TODO | 450 if (path.empty()) |
372 return false; | 451 { |
452 return false; // Cannot delete the root | |
453 } | |
454 else | |
455 { | |
456 boost::recursive_mutex::scoped_lock lock(mutex_); | |
457 | |
458 LOG(INFO) << "Deleting from WebDAV bucket: " << Toolbox::FlattenUri(path); | |
459 return root_->DeleteItem(path); | |
460 } | |
373 } | 461 } |
374 } | 462 } |