summaryrefslogtreecommitdiff
path: root/libs/pbd
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2010-07-16 15:45:24 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2010-07-16 15:45:24 +0000
commitc9b121803c3ad85c2dbb160f67a630e262bcedf5 (patch)
tree0a159ba774256a0a98f42248747303d736b955d9 /libs/pbd
parentc8e3f32533cc6f4481222781d93e7bf7c32ffe5f (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.cc70
-rw-r--r--libs/pbd/pbd/clear_dir.h12
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__ */