diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2010-07-16 15:45:24 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2010-07-16 15:45:24 +0000 |
commit | c9b121803c3ad85c2dbb160f67a630e262bcedf5 (patch) | |
tree | 0a159ba774256a0a98f42248747303d736b955d9 /libs/pbd | |
parent | c8e3f32533cc6f4481222781d93e7bf7c32ffe5f (diff) |
add new files
git-svn-id: svn://localhost/ardour2/branches/3.0@7427 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd')
-rw-r--r-- | libs/pbd/clear_dir.cc | 70 | ||||
-rw-r--r-- | libs/pbd/pbd/clear_dir.h | 12 |
2 files changed, 82 insertions, 0 deletions
diff --git a/libs/pbd/clear_dir.cc b/libs/pbd/clear_dir.cc new file mode 100644 index 0000000000..1966605af6 --- /dev/null +++ b/libs/pbd/clear_dir.cc @@ -0,0 +1,70 @@ +#include <string> +#include <dirent.h> +#include <unistd.h> +#include <sys/stat.h> +#include <errno.h> +#include <string.h> + +#include "pbd/error.h" +#include "pbd/compose.h" +#include "pbd/clear_dir.h" + +#include "i18n.h" + +using namespace PBD; +using namespace std; + +int +PBD::clear_directory (const string& dir, size_t* size, vector<string>* paths) +{ + struct dirent* dentry; + struct stat statbuf; + DIR* dead; + int ret = 0; + + if ((dead = ::opendir (dir.c_str())) == 0) { + return -1; + } + + while ((dentry = ::readdir (dead)) != 0) { + + /* avoid '.' and '..' */ + + if ((dentry->d_name[0] == '.' && dentry->d_name[1] == '\0') || + (dentry->d_name[2] == '\0' && dentry->d_name[0] == '.' && dentry->d_name[1] == '.')) { + continue; + } + + string fullpath; + + fullpath = dir; + fullpath += '/'; + fullpath += dentry->d_name; + + if (::stat (fullpath.c_str(), &statbuf)) { + continue; + } + + if (!S_ISREG (statbuf.st_mode)) { + continue; + } + + if (::unlink (fullpath.c_str())) { + error << string_compose (_("cannot remove file %1 (%2)"), fullpath, strerror (errno)) + << endmsg; + ret = 1; + } + + if (paths) { + paths->push_back (dentry->d_name); + } + + if (size) { + *size += statbuf.st_size; + } + } + + ::closedir (dead); + + return ret; +} diff --git a/libs/pbd/pbd/clear_dir.h b/libs/pbd/pbd/clear_dir.h new file mode 100644 index 0000000000..690a48d9c8 --- /dev/null +++ b/libs/pbd/pbd/clear_dir.h @@ -0,0 +1,12 @@ +#ifndef __pbd_clear_dir_h__ +#define __pbd_clear_dir_h__ + +#include <string> +#include <vector> +#include <sys/types.h> + +namespace PBD { + int clear_directory (const std::string&, size_t* = 0, std::vector<std::string>* = 0); +} + +#endif /* __pbd_clear_dir_h__ */ |