replace use of Gio:: for plugin state

This commit is contained in:
Robin Gareus 2014-03-22 17:40:43 +01:00
parent 1d85ab27a7
commit ba128eea50
3 changed files with 38 additions and 22 deletions

View 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;
}

View 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;
}
}

View 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__ */