diff options
author | Tim Mayberry <mojofunk@gmail.com> | 2014-06-19 22:31:13 +1000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2014-06-25 12:40:10 -0400 |
commit | 257897392ad00aa36a71df4ec84c9784ca1bff80 (patch) | |
tree | 650e22d84b49ad4da2c2f7e6b54ed394bef61168 /libs | |
parent | 64856a5862fc6e8792662e63da0c440e7305fba8 (diff) |
Add remove_directory_internal function and use it in PBD::clear_directory and PBD::remove_directory
Diffstat (limited to 'libs')
-rw-r--r-- | libs/pbd/clear_dir.cc | 51 |
1 files changed, 14 insertions, 37 deletions
diff --git a/libs/pbd/clear_dir.cc b/libs/pbd/clear_dir.cc index b5d483f5f4..08c932c339 100644 --- a/libs/pbd/clear_dir.cc +++ b/libs/pbd/clear_dir.cc @@ -47,14 +47,14 @@ using namespace PBD; using namespace std; int -PBD::clear_directory (const string& dir, size_t* size, vector<string>* paths) +remove_directory_internal (const string& dir, size_t* size, vector<string>* paths, + bool just_remove_files) { vector<string> tmp_paths; struct stat statbuf; int ret = 0; - // we are only removing files, not the directory structure - get_directory_contents (dir, tmp_paths, true, true); + get_directory_contents (dir, tmp_paths, just_remove_files, true); for (vector<string>::const_iterator i = tmp_paths.begin(); i != tmp_paths.end(); ++i) { @@ -63,8 +63,8 @@ PBD::clear_directory (const string& dir, size_t* size, vector<string>* paths) continue; } - if (::g_unlink (i->c_str())) { - error << string_compose (_("cannot remove file %1 (%2)"), *i, strerror (errno)) + if (::g_remove (i->c_str())) { + error << string_compose (_("cannot remove path %1 (%2)"), *i, strerror (errno)) << endmsg; ret = 1; } @@ -82,38 +82,15 @@ PBD::clear_directory (const string& dir, size_t* size, vector<string>* paths) return ret; } +int +PBD::clear_directory (const string& dir, size_t* size, vector<string>* paths) +{ + return remove_directory_internal (dir, size, paths, true); +} + // 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; - } - ::closedir (dead); +PBD::remove_directory (const std::string& dir) +{ + remove_directory_internal (dir, 0, 0, false); } |