summaryrefslogtreecommitdiff
path: root/libs/pbd/clear_dir.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2014-04-14 12:53:30 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2014-04-14 12:53:30 -0400
commit99bf5d9eeda1e5e1811d660c0c22bb5a2d4984c0 (patch)
tree575dfd6b04936b46787cbc5358e169bfbfc63380 /libs/pbd/clear_dir.cc
parenteef4e1efee2ae76fac181c078b46ca3bc6d33d2e (diff)
backport 1d85ab27a7e and ba128eea from cairocanvas branch to remove GIO (possible hotfix release)
Diffstat (limited to 'libs/pbd/clear_dir.cc')
-rw-r--r--libs/pbd/clear_dir.cc37
1 files changed, 37 insertions, 0 deletions
diff --git a/libs/pbd/clear_dir.cc b/libs/pbd/clear_dir.cc
index 29410d41e5..a7564447ab 100644
--- a/libs/pbd/clear_dir.cc
+++ b/libs/pbd/clear_dir.cc
@@ -24,6 +24,8 @@
#include <errno.h>
#include <string.h>
+#include <glib.h>
+#include <glib/gstdio.h>
#include <glibmm/miscutils.h>
#include "pbd/error.h"
@@ -85,3 +87,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;
+ }
+}