8 #include <glibmm/miscutils.h>
10 #include "pbd/error.h"
11 #include "pbd/compose.h"
12 #include "pbd/clear_dir.h"
20 PBD::clear_directory (const string
& dir
, size_t* size
, vector
<string
>* paths
)
22 struct dirent
* dentry
;
27 if ((dead
= ::opendir (dir
.c_str())) == 0) {
31 while ((dentry
= ::readdir (dead
)) != 0) {
33 /* avoid '.' and '..' */
35 if ((dentry
->d_name
[0] == '.' && dentry
->d_name
[1] == '\0') ||
36 (dentry
->d_name
[2] == '\0' && dentry
->d_name
[0] == '.' && dentry
->d_name
[1] == '.')) {
40 string fullpath
= Glib::build_filename (dir
, dentry
->d_name
);
42 if (::stat (fullpath
.c_str(), &statbuf
)) {
46 if (!S_ISREG (statbuf
.st_mode
)) {
50 if (::unlink (fullpath
.c_str())) {
51 error
<< string_compose (_("cannot remove file %1 (%2)"), fullpath
, strerror (errno
))
57 paths
->push_back (dentry
->d_name
);
61 *size
+= statbuf
.st_size
;