#include <boost/utility.hpp>
+#include "pbd/clear_dir.h"
#include "pbd/pathscanner.h"
#include "pbd/compose.h"
#include "pbd/error.h"
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
{
} else {
// State is identical, decrement version and nuke directory
lilv_state_free(state);
- remove_directory(new_dir);
+ PBD::remove_directory(new_dir);
--_state_version;
}
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;
+ }
+}
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__ */