replace use of Gio:: for plugin state
authorRobin Gareus <robin@gareus.org>
Sat, 22 Mar 2014 16:40:43 +0000 (17:40 +0100)
committerRobin Gareus <robin@gareus.org>
Sat, 22 Mar 2014 16:42:26 +0000 (17:42 +0100)
libs/ardour/lv2_plugin.cc
libs/pbd/clear_dir.cc
libs/pbd/pbd/clear_dir.h

index 5c12524d78f4a0c4b4a427b7729435a5441a44f0..980c43c9b792ad6a8339ce4494881e162c7311f4 100644 (file)
@@ -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;
                }
 
index 2f9c7b772d4f618b24c773796ba83e52cfa80af0..9d2d7ed88311b4024958138a11faac3a4d2484fe 100644 (file)
@@ -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;
+       }
+}
index c0fb49d41d24172f9e3ccf13728563850a1346c0..f669b84485d5e03094f9405850977a5b614c8134 100644 (file)
@@ -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__ */