about summary refs log tree commit diff
path: root/src/libstore/build.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore/build.cc')
-rw-r--r--src/libstore/build.cc30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index a86fa0f947a0..14388a7b56dc 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -531,14 +531,28 @@ void getOwnership(const Path & path)
 }
 
 
-static void deletePathWrapped(const Path & path)
-{
-    /* When using build users and we're not root, we may not have
-       sufficient permission to delete the path.  So use the setuid
-       helper to change ownership to us. */
-    if (haveBuildUsers() && !amPrivileged())
-        getOwnership(path);
-    deletePath(path);
+void deletePathWrapped(const Path & path,
+    unsigned long long & bytesFreed)
+{
+    try {
+        /* First try to delete it ourselves. */
+        deletePath(path, bytesFreed);
+    } catch (SysError & e) {
+        /* If this failed due to a permission error, then try it with
+           the setuid helper. */
+        if (haveBuildUsers() && !amPrivileged()) {
+            getOwnership(path);
+            deletePath(path, bytesFreed);
+        } else
+            throw;
+    }
+}
+
+
+void deletePathWrapped(const Path & path)
+{
+    unsigned long long dummy;
+    deletePathWrapped(path, dummy);
 }