X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Fclear_dir.cc;h=9d2d7ed88311b4024958138a11faac3a4d2484fe;hb=c046b7c9d36d54600907565271a8ea2ceb004300;hp=2f9c7b772d4f618b24c773796ba83e52cfa80af0;hpb=2a7ed69c28c5c4606ff13b3605b9bc9c3eba607d;p=ardour.git diff --git a/libs/pbd/clear_dir.cc b/libs/pbd/clear_dir.cc index 2f9c7b772d..9d2d7ed883 100644 --- a/libs/pbd/clear_dir.cc +++ b/libs/pbd/clear_dir.cc @@ -94,3 +94,38 @@ PBD::clear_directory (const string& dir, size_t* size, vector* paths) return ret; } + +// rm -rf -- 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; + } +}