2 Copyright (C) 2012 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <io.h> // Microsoft's nearest equivalent to <unistd.h>
36 #include <glib/gstdio.h>
37 #include <glibmm/miscutils.h>
39 #include "pbd/error.h"
40 #include "pbd/compose.h"
41 #include "pbd/clear_dir.h"
49 PBD::clear_directory (const string& dir, size_t* size, vector<string>* paths)
51 struct dirent* dentry;
56 if ((dead = ::opendir (dir.c_str())) == 0) {
60 while ((dentry = ::readdir (dead)) != 0) {
62 /* avoid '.' and '..' */
64 if ((dentry->d_name[0] == '.' && dentry->d_name[1] == '\0') ||
65 (dentry->d_name[2] == '\0' && dentry->d_name[0] == '.' && dentry->d_name[1] == '.')) {
69 string fullpath = Glib::build_filename (dir, dentry->d_name);
71 if (::stat (fullpath.c_str(), &statbuf)) {
75 if (!S_ISREG (statbuf.st_mode)) {
79 if (::g_unlink (fullpath.c_str())) {
80 error << string_compose (_("cannot remove file %1 (%2)"), fullpath, strerror (errno))
86 paths->push_back (dentry->d_name);
90 *size += statbuf.st_size;
99 // rm -rf <dir> -- used to remove saved plugin state
101 PBD::remove_directory (const std::string& dir) {
103 struct dirent* dentry;
106 if ((dead = ::opendir (dir.c_str())) == 0) {
110 while ((dentry = ::readdir (dead)) != 0) {
111 if(!strcmp(dentry->d_name, ".") || !strcmp(dentry->d_name, "..")) {
115 string fullpath = Glib::build_filename (dir, dentry->d_name);
116 if (::stat (fullpath.c_str(), &statbuf)) {
120 if (S_ISDIR (statbuf.st_mode)) {
121 remove_directory(fullpath);
125 if (::g_unlink (fullpath.c_str())) {
126 error << string_compose (_("cannot remove file %1 (%2)"), fullpath, strerror (errno)) << endmsg;
129 if (::g_rmdir(dir.c_str())) {
130 error << string_compose (_("cannot remove directory %1 (%2)"), dir, strerror (errno)) << endmsg;