diff options
author | Tim Mayberry <mojofunk@gmail.com> | 2014-06-19 23:00:45 +1000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2014-06-25 12:40:10 -0400 |
commit | cb3a60493620e5965de72d34fe0c0d2cce7ec037 (patch) | |
tree | eb0aec36c0b0de2070fc27effa46f90059242317 /libs/pbd/file_utils.cc | |
parent | 257897392ad00aa36a71df4ec84c9784ca1bff80 (diff) |
Move functions in pbd/clear_dir.h/cc into pbd/file_utils.h/cc
Diffstat (limited to 'libs/pbd/file_utils.cc')
-rw-r--r-- | libs/pbd/file_utils.cc | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/libs/pbd/file_utils.cc b/libs/pbd/file_utils.cc index 9db71c25c0..1101ba6504 100644 --- a/libs/pbd/file_utils.cc +++ b/libs/pbd/file_utils.cc @@ -404,4 +404,53 @@ exists_and_writable (const std::string & p) return true; } +int +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; + + get_directory_contents (dir, tmp_paths, just_remove_files, true); + + for (vector<string>::const_iterator i = tmp_paths.begin(); + i != tmp_paths.end(); ++i) { + + if (g_stat (i->c_str(), &statbuf)) { + continue; + } + + if (::g_remove (i->c_str())) { + error << string_compose (_("cannot remove path %1 (%2)"), *i, strerror (errno)) + << endmsg; + ret = 1; + } + + if (paths) { + paths->push_back (Glib::path_get_basename(*i)); + } + + if (size) { + *size += statbuf.st_size; + } + + } + + return ret; +} + +int +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 +remove_directory (const std::string& dir) +{ + remove_directory_internal (dir, 0, 0, false); +} + } // namespace PBD |