about summary refs log tree commit diff
path: root/src/libutil
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-12-15T21·11+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-12-15T21·11+0000
commit530b27df1e71852580d8b0d474543aeffe65618f (patch)
tree166f79c170b19ad82ca6bf9a3c77b96325b72aa1 /src/libutil
parent5144f750c471cdb629750e96ddc913fb01fb9eef (diff)
* `nix-store --gc' prints out the number of bytes freed on stdout
  (even when it is interrupted by a signal).

Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.cc16
-rw-r--r--src/libutil/util.hh5
2 files changed, 17 insertions, 4 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 2e684e9c14..5a728617db 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -194,7 +194,7 @@ void writeFile(const Path & path, const string & s)
 }
 
 
-static void _deletePath(const Path & path)
+static void _deletePath(const Path & path, unsigned long long & bytesFreed)
 {
     checkInterrupt();
 
@@ -204,6 +204,8 @@ static void _deletePath(const Path & path)
     if (lstat(path.c_str(), &st))
 	throw SysError(format("getting attributes of path `%1%'") % path);
 
+    bytesFreed += st.st_size;
+
     if (S_ISDIR(st.st_mode)) {
 	Strings names = readDirectory(path);
 
@@ -214,7 +216,7 @@ static void _deletePath(const Path & path)
 	}
 
 	for (Strings::iterator i = names.begin(); i != names.end(); ++i)
-            _deletePath(path + "/" + *i);
+            _deletePath(path + "/" + *i, bytesFreed);
     }
 
     if (remove(path.c_str()) == -1)
@@ -224,9 +226,17 @@ static void _deletePath(const Path & path)
 
 void deletePath(const Path & path)
 {
+    unsigned long long dummy;
+    deletePath(path, dummy);
+}
+
+
+void deletePath(const Path & path, unsigned long long & bytesFreed)
+{
     startNest(nest, lvlDebug,
         format("recursively deleting path `%1%'") % path);
-    _deletePath(path);
+    bytesFreed = 0;
+    _deletePath(path, bytesFreed);
 }
 
 
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 9e7eb11bd1..9601e65b3c 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -98,9 +98,12 @@ string readFile(const Path & path);
 void writeFile(const Path & path, const string & s);
 
 /* Delete a path; i.e., in the case of a directory, it is deleted
-   recursively.  Don't use this at home, kids. */
+   recursively.  Don't use this at home, kids.  The second variant
+   returns the number of bytes freed. */
 void deletePath(const Path & path);
 
+void deletePath(const Path & path, unsigned long long & bytesFreed);
+
 /* Make a path read-only recursively. */
 void makePathReadOnly(const Path & path);