about summary refs log tree commit diff
path: root/src/util.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-08-08T14·55+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-08-08T14·55+0000
commitc602930e08a508fce76b16f6f7f1fdfaed3b91ab (patch)
tree692666018067e0beb7c0810efafd38db78aadad7 /src/util.cc
parent4b7b0bd12ca59f84b7adada64818086ece684447 (diff)
* deletePath(): some operating systems (e.g., Mac OS X) don't like it
  when we delete entries from a directory while we are reading it.
  So read the directory into memory, then delete its contents.

Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/util.cc b/src/util.cc
index 3c9a31acc172..1e1c799ece6d 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -108,21 +108,28 @@ bool pathExists(const string & path)
 
 void deletePath(string path)
 {
+    msg(lvlVomit, format("deleting path `%1%'") % path);
+
     struct stat st;
     if (lstat(path.c_str(), &st))
         throw SysError(format("getting attributes of path %1%") % path);
 
     if (S_ISDIR(st.st_mode)) {
+	Strings names;
+
         DIR * dir = opendir(path.c_str());
 
         struct dirent * dirent;
         while (errno = 0, dirent = readdir(dir)) {
             string name = dirent->d_name;
             if (name == "." || name == "..") continue;
-            deletePath(path + "/" + name);
+	    names.push_back(name);
         }
 
         closedir(dir); /* !!! close on exception */
+
+	for (Strings::iterator i = names.begin(); i != names.end(); i++)
+            deletePath(path + "/" + *i);
     }
 
     if (remove(path.c_str()) == -1)