summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-09-20 16:03:35 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-09-20 16:03:35 +0200
commitd0cc9153d53dd4bc8dadf8bbcbe4ac72dfbbb61e (patch)
tree37d55a434528ff8d53e46393eff7ebd5529b52aa /src
parent78db15a780cc5389fc6e01d500d5c91bdd8bc422 (diff)
downloadmad-d0cc9153d53dd4bc8dadf8bbcbe4ac72dfbbb61e.tar
mad-d0cc9153d53dd4bc8dadf8bbcbe4ac72dfbbb61e.zip
Extended StorageManager to provide copy and remove methods.
Diffstat (limited to 'src')
-rw-r--r--src/Common/StorageBackend.h2
-rw-r--r--src/Common/StorageManager.cpp16
-rw-r--r--src/Common/StorageManager.h2
-rw-r--r--src/modules/StorageBackendFile/StorageBackendFile.cpp22
-rw-r--r--src/modules/StorageBackendFile/StorageBackendFile.h2
5 files changed, 44 insertions, 0 deletions
diff --git a/src/Common/StorageBackend.h b/src/Common/StorageBackend.h
index abec185..24bb437 100644
--- a/src/Common/StorageBackend.h
+++ b/src/Common/StorageBackend.h
@@ -45,6 +45,8 @@ class StorageBackend {
virtual void store(const std::string &type, const std::string &name, const XmlData *data) throw (Core::Exception) = 0;
virtual boost::shared_ptr<XmlData> load(const std::string &type, const std::string &name) throw (Core::Exception) = 0;
+ virtual void copy(const std::string &type, const std::string &name, const std::string &newName) throw (Core::Exception) = 0;
+ virtual void rename(const std::string &type, const std::string &name, const std::string &newName) throw (Core::Exception) = 0;
virtual void remove(const std::string &type, const std::string &name) throw (Core::Exception) = 0;
public:
diff --git a/src/Common/StorageManager.cpp b/src/Common/StorageManager.cpp
index 3b14554..5b5fc65 100644
--- a/src/Common/StorageManager.cpp
+++ b/src/Common/StorageManager.cpp
@@ -76,6 +76,22 @@ boost::shared_ptr<XmlData> StorageManager::load(const std::string &type, const s
return backend->load(type, name);
}
+void StorageManager::copy(const std::string &type, const std::string &name, const std::string &newName) throw (Core::Exception) {
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
+ if(!backend)
+ throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
+
+ backend->copy(type, name, newName);
+}
+
+void StorageManager::rename(const std::string &type, const std::string &name, const std::string &newName) throw (Core::Exception) {
+ boost::shared_lock<boost::shared_mutex> lock(mutex);
+ if(!backend)
+ throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
+
+ backend->rename(type, name, newName);
+}
+
void StorageManager::remove(const std::string &type, const std::string &name) throw (Core::Exception) {
boost::shared_lock<boost::shared_mutex> lock(mutex);
if(!backend)
diff --git a/src/Common/StorageManager.h b/src/Common/StorageManager.h
index 594c294..d6cb5f5 100644
--- a/src/Common/StorageManager.h
+++ b/src/Common/StorageManager.h
@@ -59,6 +59,8 @@ class MAD_COMMON_EXPORT StorageManager {
void store(const std::string &type, const std::string &name, const XmlData *data) throw (Core::Exception);
boost::shared_ptr<XmlData> load(const std::string &type, const std::string &name) throw (Core::Exception);
+ void copy(const std::string &type, const std::string &name, const std::string &newName) throw (Core::Exception);
+ void rename(const std::string &type, const std::string &name, const std::string &newName) throw (Core::Exception);
void remove(const std::string &type, const std::string &name) throw (Core::Exception);
};
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<Common::XmlData> StorageBackendFile::load(const std::string &t
return boost::shared_ptr<Common::XmlData>(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<boost::shared_mutex> 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<boost::shared_mutex> 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<boost::shared_mutex> 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<Common::XmlData> 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: