about summary refs log tree commit diff
path: root/src/libutil/util.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-02-24T16·44+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-02-24T16·44+0100
commit152b1d6bf9c89b4db9848475e3000821e159d479 (patch)
tree2667ff6b2f8f91269fbb3a12fee4aa2fc53bdd04 /src/libutil/util.cc
parent28e7e29abdcdaf60ba8a5fad3738fe4a8f3db9a8 (diff)
deletePath(): Succeed if path doesn't exist
Also makes it robust against concurrent deletions.
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r--src/libutil/util.cc12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index def0525abc..3becbbabc2 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -320,9 +320,11 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed)
 {
     checkInterrupt();
 
-    printMsg(lvlVomit, format("%1%") % path);
-
-    struct stat st = lstat(path);
+    struct stat st;
+    if (lstat(path.c_str(), &st) == -1) {
+        if (errno == ENOENT) return;
+        throw SysError(format("getting status of ‘%1%’") % path);
+    }
 
     if (!S_ISDIR(st.st_mode) && st.st_nlink == 1)
         bytesFreed += st.st_blocks * 512;
@@ -338,8 +340,10 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed)
             _deletePath(path + "/" + i.name, bytesFreed);
     }
 
-    if (remove(path.c_str()) == -1)
+    if (remove(path.c_str()) == -1) {
+        if (errno == ENOENT) return;
         throw SysError(format("cannot unlink ‘%1%’") % path);
+    }
 }