about summary refs log tree commit diff
path: root/src/libstore/store-api.hh
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2008-06-18T09·34+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2008-06-18T09·34+0000
commita72709afd8ffe35613a6bacd698a36395e095a48 (patch)
tree2f549bafbed92a53bd6faea1da43667307af7593 /src/libstore/store-api.hh
parent934c58aa381f5eacc86304ba7f5c6775ff456cd5 (diff)
* Some refactoring: put the GC options / results in separate structs.
* The garbage collector now also prints the number of blocks freed.

Diffstat (limited to 'src/libstore/store-api.hh')
-rw-r--r--src/libstore/store-api.hh113
1 files changed, 78 insertions, 35 deletions
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index a50dcf6451..760e71adc7 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -16,14 +16,82 @@ namespace nix {
 typedef std::map<Path, Path> Roots;
 
 
-/* Garbage collector operation. */
-typedef enum {
-    gcReturnRoots,
-    gcReturnLive,
-    gcReturnDead,
-    gcDeleteDead,
-    gcDeleteSpecific,
-} GCAction;
+
+
+struct GCOptions
+{
+    /* Garbage collector operation:
+
+       - `gcReturnRoots': find and return the set of roots for the
+         garbage collector.  These are the store paths symlinked to in
+         the `gcroots' directory.
+
+       - `gcReturnLive': return the set of paths reachable from
+         (i.e. in the closure of) the roots.
+
+       - `gcReturnDead': return the set of paths not reachable from
+         the roots.
+
+       - `gcDeleteDead': actually delete the latter set.
+
+       - `gcDeleteSpecific': delete the paths listed in
+          `pathsToDelete', insofar as they are not reachable.
+    */
+    typedef enum {
+        gcReturnRoots,
+        gcReturnLive,
+        gcReturnDead,
+        gcDeleteDead,
+        gcDeleteSpecific,
+    } GCAction;
+
+    GCAction action;
+
+    /* If `ignoreLiveness' is set, then reachability from the roots is
+       ignored (dangerous!).  However, the paths must still be
+       unreferenced *within* the store (i.e., there can be no other
+       store paths that depend on them). */
+    bool ignoreLiveness;
+
+    /* For `gcDeleteSpecific', the paths to delete. */
+    PathSet pathsToDelete;
+
+    /* Stop after at least `maxFreed' bytes have been freed. */
+    unsigned long long maxFreed;
+
+    /* Stop after the number of hard links to the Nix store directory
+       has dropped to at least `maxLinks'. */
+    unsigned int maxLinks;
+
+    GCOptions() 
+    {
+        action = gcDeleteDead;
+        ignoreLiveness = false;
+        maxFreed = ULLONG_MAX;
+        maxLinks = UINT_MAX;
+    }
+};
+
+
+struct GCResults 
+{
+    /* Depending on the action, the GC roots, or the paths that would
+       be or have been deleted. */
+    PathSet paths;
+
+    /* For `gcReturnDead', `gcDeleteDead' and `gcDeleteSpecific', the
+       number of bytes that would be or was freed. */
+    unsigned long long bytesFreed;
+
+    /* The number of file system blocks that would be or was freed. */
+    unsigned long long blocksFreed;
+
+    GCResults()
+    {
+        bytesFreed = 0;
+        blocksFreed = 0;
+    }
+};
 
 
 class StoreAPI 
@@ -137,33 +205,8 @@ public:
        outside of the Nix store that point to `storePath'.  */
     virtual Roots findRoots() = 0;
 
-    /* Depending on `action', this function does the following:
-
-       - `gcReturnRoots': find and return the set of roots for the
-         garbage collector.  These are the store paths symlinked to in
-         the `gcroots' directory.
-
-       - `gcReturnLive': return the set of paths reachable from
-         (i.e. in the closure of) the roots.
-
-       - `gcReturnDead': return the set of paths not reachable from
-         the roots.
-
-       - `gcDeleteDead': actually delete the latter set.
-
-       - `gcDeleteSpecific': delete the paths listed in
-         `pathsToDelete', insofar as they are not reachable.
-
-       If `ignoreLiveness' is set, then reachability from the roots is
-       ignored (dangerous!).  However, the paths must still be
-       unreferenced *within* the store (i.e., there can be no other
-       store paths that depend on them).
-
-       For `gcReturnDead', `gcDeleteDead' and `gcDeleteSpecific', the
-       number of bytes that would be or was freed is returned in
-       `bytesFreed'. */
-    virtual void collectGarbage(GCAction action, const PathSet & pathsToDelete,
-        bool ignoreLiveness, PathSet & result, unsigned long long & bytesFreed) = 0;
+    /* Perform a garbage collection. */
+    virtual void collectGarbage(const GCOptions & options, GCResults & results) = 0;
 };