From d0cc9153d53dd4bc8dadf8bbcbe4ac72dfbbb61e Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 20 Sep 2009 16:03:35 +0200 Subject: Extended StorageManager to provide copy and remove methods. --- .../StorageBackendFile/StorageBackendFile.cpp | 22 ++++++++++++++++++++++ .../StorageBackendFile/StorageBackendFile.h | 2 ++ 2 files changed, 24 insertions(+) (limited to 'src/modules/StorageBackendFile') diff --git a/src/modules/StorageBackendFile/StorageBackendFile.cpp b/src/modules/StorageBackendFile/StorageBackendFile.cpp index c8bc4f7..6a9242d 100644 --- a/src/modules/StorageBackendFile/StorageBackendFile.cpp +++ b/src/modules/StorageBackendFile/StorageBackendFile.cpp @@ -150,6 +150,28 @@ boost::shared_ptr StorageBackendFile::load(const std::string &t return boost::shared_ptr(new Common::XmlData(path.file_string())); } +void StorageBackendFile::copy(const std::string &type, const std::string &name, const std::string &newName) throw (Core::Exception) { + boost::lock_guard lock(mutex); + + if(!configured) + throw Core::Exception(Core::Exception::NOT_AVAILABLE); + + boost::filesystem::path path = getFileName(type, name); + boost::filesystem::path newPath = getFileName(type, newName); + boost::filesystem::copy_file(path, newPath); +} + +void StorageBackendFile::rename(const std::string &type, const std::string &name, const std::string &newName) throw (Core::Exception) { + boost::lock_guard lock(mutex); + + if(!configured) + throw Core::Exception(Core::Exception::NOT_AVAILABLE); + + boost::filesystem::path path = getFileName(type, name); + boost::filesystem::path newPath = getFileName(type, newName); + boost::filesystem::rename(path, newPath); +} + void StorageBackendFile::remove(const std::string &type, const std::string &name) throw (Core::Exception) { boost::lock_guard lock(mutex); diff --git a/src/modules/StorageBackendFile/StorageBackendFile.h b/src/modules/StorageBackendFile/StorageBackendFile.h index 5cce4fc..9994500 100644 --- a/src/modules/StorageBackendFile/StorageBackendFile.h +++ b/src/modules/StorageBackendFile/StorageBackendFile.h @@ -56,6 +56,8 @@ class StorageBackendFile : public Common::StorageBackend, private Core::Configur virtual void store(const std::string &type, const std::string &name, const Common::XmlData *data) throw (Core::Exception); virtual boost::shared_ptr load(const std::string &type, const std::string &name) throw (Core::Exception); + virtual void copy(const std::string &type, const std::string &name, const std::string &newName) throw (Core::Exception); + virtual void rename(const std::string &type, const std::string &name, const std::string &newName) throw (Core::Exception); virtual void remove(const std::string &type, const std::string &name) throw (Core::Exception); public: -- cgit v1.2.3