9 #include "pbd/compose.h"
10 #include "pbd/clear_dir.h"
18 PBD::clear_directory (const string& dir, size_t* size, vector<string>* paths)
20 struct dirent* dentry;
25 if ((dead = ::opendir (dir.c_str())) == 0) {
29 while ((dentry = ::readdir (dead)) != 0) {
31 /* avoid '.' and '..' */
33 if ((dentry->d_name[0] == '.' && dentry->d_name[1] == '\0') ||
34 (dentry->d_name[2] == '\0' && dentry->d_name[0] == '.' && dentry->d_name[1] == '.')) {
42 fullpath += dentry->d_name;
44 if (::stat (fullpath.c_str(), &statbuf)) {
48 if (!S_ISREG (statbuf.st_mode)) {
52 if (::unlink (fullpath.c_str())) {
53 error << string_compose (_("cannot remove file %1 (%2)"), fullpath, strerror (errno))
59 paths->push_back (dentry->d_name);
63 *size += statbuf.st_size;