about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-08-11T20·26+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-08-11T20·26+0000
commit4250b641d8e8edc4cb7def9bc463c7e4ff82e144 (patch)
treee90895b2154163a1b0be61616220e4215cf6159c /src
parent92f7dfa5b73e44f7584eaed726927450a29a48b8 (diff)
* `nix-store --gc --print-dead': print the total size of the store
  objects that would be freed.

Diffstat (limited to 'src')
-rw-r--r--src/libstore/gc.cc9
-rw-r--r--src/nix-store/main.cc15
2 files changed, 19 insertions, 5 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index 01d85d4d525e..37fde29ca035 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -515,6 +515,15 @@ void collectGarbage(GCAction action, const PathSet & pathsToDelete,
         debug(format("dead path `%1%'") % *i);
         result.insert(*i);
 
+        /* If just returning the set of dead paths, we also return the
+           space that would be freed if we deleted them. */
+        if (action == gcReturnDead) {
+            struct stat st;
+            if (lstat(i->c_str(), &st) == -1)
+                st.st_size = 0;
+            bytesFreed += st.st_size;
+        }
+
         if (action == gcDeleteDead || action == gcDeleteSpecific) {
 
 #ifndef __CYGWIN__
diff --git a/src/nix-store/main.cc b/src/nix-store/main.cc
index 132516cd9396..fc458a246c4a 100644
--- a/src/nix-store/main.cc
+++ b/src/nix-store/main.cc
@@ -492,13 +492,17 @@ static void opCheckValidity(Strings opFlags, Strings opArgs)
 
 struct PrintFreed 
 {
-    bool show;
+    bool show, dryRun;
     unsigned long long bytesFreed;
-    PrintFreed(bool _show) : bytesFreed(0), show(_show) { }
+    PrintFreed(bool show, bool dryRun)
+        : bytesFreed(0), show(show), dryRun(dryRun) { }
     ~PrintFreed() 
     {
         if (show)
-            cout << format("%d bytes freed (%.2f MiB)\n")
+            cout << format(
+                (dryRun
+                    ? "%d bytes would be freed (%.2f MiB)\n"
+                    : "%d bytes freed (%.2f MiB)\n"))
                 % bytesFreed % (bytesFreed / (1024.0 * 1024.0));
     }
 };
@@ -518,7 +522,8 @@ static void opGC(Strings opFlags, Strings opArgs)
         else throw UsageError(format("bad sub-operation `%1%' in GC") % *i);
 
     PathSet result;
-    PrintFreed freed(action == gcDeleteDead);
+    PrintFreed freed(action == gcDeleteDead || action == gcReturnDead,
+        action == gcReturnDead);
     collectGarbage(action, PathSet(), false, result, freed.bytesFreed);
 
     if (action != gcDeleteDead) {
@@ -546,7 +551,7 @@ static void opDelete(Strings opFlags, Strings opArgs)
         pathsToDelete.insert(fixPath(*i));
     
     PathSet dummy;
-    PrintFreed freed(true);
+    PrintFreed freed(true, false);
     collectGarbage(gcDeleteSpecific, pathsToDelete, ignoreLiveness,
         dummy, freed.bytesFreed);
 }