# HG changeset patch # User Sebastien Jodogne # Date 1602069593 -7200 # Node ID ca2a55a62c81b343fb2598aa4af093b8136c1f6c # Parent 688435755466e3b95a4b2a5ded805ac12f64343f implementation of DELETE in class WebDavStorage diff -r 688435755466 -r ca2a55a62c81 OrthancFramework/Sources/HttpServer/HttpServer.cpp --- a/OrthancFramework/Sources/HttpServer/HttpServer.cpp Wed Oct 07 13:00:57 2020 +0200 +++ b/OrthancFramework/Sources/HttpServer/HttpServer.cpp Wed Oct 07 13:19:53 2020 +0200 @@ -969,7 +969,8 @@ else if (method == "DELETE") { - if (bucket->second->DeleteItem(path)) + if (!path.empty() && // Cannot delete the root + bucket->second->DeleteItem(path)) { output.SendStatus(HttpStatus_204_NoContent); } diff -r 688435755466 -r ca2a55a62c81 OrthancFramework/Sources/HttpServer/WebDavStorage.cpp --- a/OrthancFramework/Sources/HttpServer/WebDavStorage.cpp Wed Oct 07 13:00:57 2020 +0200 +++ b/OrthancFramework/Sources/HttpServer/WebDavStorage.cpp Wed Oct 07 13:19:53 2020 +0200 @@ -112,8 +112,14 @@ typedef std::map Files; typedef std::map Subfolders; - Files files_; - Subfolders subfolders_; + Files files_; + Subfolders subfolders_; + boost::posix_time::ptime time_; + + void Touch() + { + time_ = boost::posix_time::second_clock::universal_time(); + } void CheckName(const std::string& name) { @@ -134,6 +140,11 @@ } public: + StorageFolder() + { + Touch(); + } + ~StorageFolder() { for (Files::iterator it = files_.begin(); it != files_.end(); ++it) @@ -149,6 +160,11 @@ } } + const boost::posix_time::ptime& GetModificationTime() const + { + return time_; + } + const StorageFile* LookupFile(const std::string& name) const { Files::const_iterator found = files_.find(name); @@ -175,6 +191,7 @@ else { subfolders_[name] = new StorageFolder; + Touch(); return true; } } @@ -205,6 +222,7 @@ found->second->SetContent(content, mime, isMemory); } + Touch(); return true; } @@ -245,7 +263,68 @@ for (Subfolders::const_iterator it = subfolders_.begin(); it != subfolders_.end(); ++it) { - collection.AddResource(new Folder(it->first)); + std::unique_ptr f(new Folder(it->first)); + f->SetModificationTime(it->second->GetModificationTime()); + collection.AddResource(f.release()); + } + } + + bool DeleteItem(const std::vector& path) + { + if (path.size() == 0) + { + throw OrthancException(ErrorCode_InternalError); + } + else if (path.size() == 1) + { + { + Files::iterator f = files_.find(path[0]); + if (f != files_.end()) + { + assert(f->second != NULL); + delete f->second; + files_.erase(f); + Touch(); + return true; + } + } + + { + Subfolders::iterator f = subfolders_.find(path[0]); + if (f != subfolders_.end()) + { + assert(f->second != NULL); + delete f->second; + subfolders_.erase(f); + Touch(); + return true; + } + } + + return false; + } + else + { + Subfolders::iterator f = subfolders_.find(path[0]); + if (f != subfolders_.end()) + { + assert(f->second != NULL); + + std::vector p(path.begin() + 1, path.end()); + if (f->second->DeleteItem(p)) + { + Touch(); + return true; + } + else + { + return false; + } + } + else + { + return false; + } } } }; @@ -368,7 +447,16 @@ bool WebDavStorage::DeleteItem(const std::vector& path) { - // TODO - return false; + if (path.empty()) + { + return false; // Cannot delete the root + } + else + { + boost::recursive_mutex::scoped_lock lock(mutex_); + + LOG(INFO) << "Deleting from WebDAV bucket: " << Toolbox::FlattenUri(path); + return root_->DeleteItem(path); + } } } diff -r 688435755466 -r ca2a55a62c81 OrthancServer/Sources/main.cpp --- a/OrthancServer/Sources/main.cpp Wed Oct 07 13:00:57 2020 +0200 +++ b/OrthancServer/Sources/main.cpp Wed Oct 07 13:19:53 2020 +0200 @@ -1634,9 +1634,9 @@ UriComponents root; // TODO root.push_back("a"); root.push_back("b"); - //httpServer.Register(root, new WebDavStorage(true)); + httpServer.Register(root, new WebDavStorage(true)); //httpServer.Register(root, new DummyBucket(context, true)); - httpServer.Register(root, new DummyBucket2(context)); + //httpServer.Register(root, new DummyBucket2(context)); } if (httpServer.GetPortNumber() < 1024)