diff options
author | Robin Gareus <robin@gareus.org> | 2014-03-22 17:40:43 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2014-03-22 17:42:26 +0100 |
commit | ba128eea5027d9b9b1f54003579ee1d948c6542d (patch) | |
tree | e502b2d6cf1d5197d088939a4a111ef46556e967 /libs | |
parent | 1d85ab27a7e4a18e9a513b1fff9905aa92fe299a (diff) |
replace use of Gio:: for plugin state
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ardour/lv2_plugin.cc | 24 | ||||
-rw-r--r-- | libs/pbd/clear_dir.cc | 35 | ||||
-rw-r--r-- | libs/pbd/pbd/clear_dir.h | 1 |
3 files changed, 38 insertions, 22 deletions
diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index 5c12524d78..980c43c9b7 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -32,6 +32,7 @@ #include <boost/utility.hpp> +#include "pbd/clear_dir.h" #include "pbd/pathscanner.h" #include "pbd/compose.h" #include "pbd/error.h" @@ -881,27 +882,6 @@ LV2Plugin::lv2_state_make_path(LV2_State_Make_Path_Handle handle, return g_strndup(abs_path.c_str(), abs_path.length()); } -static void -remove_directory(const std::string& path) -{ - if (!Glib::file_test(path, Glib::FILE_TEST_IS_DIR)) { - warning << string_compose("\"%1\" is not a directory", path) << endmsg; - return; - } - - Glib::RefPtr<Gio::File> dir = Gio::File::create_for_path(path); - Glib::RefPtr<Gio::FileEnumerator> e = dir->enumerate_children(); - Glib::RefPtr<Gio::FileInfo> fi; - while ((fi = e->next_file())) { - if (fi->get_type() == Gio::FILE_TYPE_DIRECTORY) { - remove_directory(fi->get_name()); - } else { - dir->get_child(fi->get_name())->remove(); - } - } - dir->remove(); -} - void LV2Plugin::add_state(XMLNode* root) const { @@ -953,7 +933,7 @@ LV2Plugin::add_state(XMLNode* root) const } else { // State is identical, decrement version and nuke directory lilv_state_free(state); - remove_directory(new_dir); + PBD::remove_directory(new_dir); --_state_version; } diff --git a/libs/pbd/clear_dir.cc b/libs/pbd/clear_dir.cc index 2f9c7b772d..9d2d7ed883 100644 --- a/libs/pbd/clear_dir.cc +++ b/libs/pbd/clear_dir.cc @@ -94,3 +94,38 @@ PBD::clear_directory (const string& dir, size_t* size, vector<string>* paths) return ret; } + +// rm -rf <dir> -- used to remove saved plugin state +void +PBD::remove_directory (const std::string& dir) { + DIR* dead; + struct dirent* dentry; + struct stat statbuf; + + if ((dead = ::opendir (dir.c_str())) == 0) { + return; + } + + while ((dentry = ::readdir (dead)) != 0) { + if(!strcmp(dentry->d_name, ".") || !strcmp(dentry->d_name, "..")) { + continue; + } + + string fullpath = Glib::build_filename (dir, dentry->d_name); + if (::stat (fullpath.c_str(), &statbuf)) { + continue; + } + + if (S_ISDIR (statbuf.st_mode)) { + remove_directory(fullpath); + continue; + } + + if (::g_unlink (fullpath.c_str())) { + error << string_compose (_("cannot remove file %1 (%2)"), fullpath, strerror (errno)) << endmsg; + } + } + if (::g_rmdir(dir.c_str())) { + error << string_compose (_("cannot remove directory %1 (%2)"), dir, strerror (errno)) << endmsg; + } +} diff --git a/libs/pbd/pbd/clear_dir.h b/libs/pbd/pbd/clear_dir.h index c0fb49d41d..f669b84485 100644 --- a/libs/pbd/pbd/clear_dir.h +++ b/libs/pbd/pbd/clear_dir.h @@ -28,6 +28,7 @@ namespace PBD { LIBPBD_API int clear_directory (const std::string&, size_t* = 0, std::vector<std::string>* = 0); + LIBPBD_API void remove_directory (const std::string& dir); } #endif /* __pbd_clear_dir_h__ */ |