@@ -9,52 +9,35 @@ namespace nix {
99
1010typedef std::unordered_map<StorePath, std::unordered_set<std::string>> Roots;
1111
12+ /* Return either live (reachable) or dead (unreachable) paths */
13+ enum class GCReturn { Live, Dead };
1214
13- struct GCOptions
14- {
15- /* *
16- * Garbage collector operation:
17- *
18- * - `gcReturnLive`: return the set of paths reachable from
19- * (i.e. in the closure of) the roots.
20- *
21- * - `gcReturnDead`: return the set of paths not reachable from
22- * the roots.
23- *
24- * - `gcDeleteDead`: actually delete the latter set.
25- *
26- * - `gcDeleteSpecific`: delete the paths listed in
27- * `pathsToDelete`, insofar as they are not reachable.
28- */
29- typedef enum {
30- gcReturnLive,
31- gcReturnDead,
32- gcDeleteDead,
33- gcDeleteSpecific,
34- } GCAction;
15+ /* Set of paths to delete, and whether their transitive closures should be deleted as well */
16+ struct GCPathsToDelete {
17+ StorePathSet paths;
18+ bool recursive;
19+ };
3520
36- GCAction action{gcDeleteDead};
21+ /* Delete either a given set of paths, or all dead paths */
22+ struct GCDelete {
23+ /* Delete this set, or all dead paths if it is std::nullopt */
24+ std::optional<GCPathsToDelete> pathsToDelete;
25+ /* If `ignoreLiveness' is set, then reachability from the roots is
26+ ignored (dangerous!). However, the paths must still be
27+ unreferenced *within* the store (i.e., there can be no other
28+ store paths that depend on them). */
29+ bool ignoreLiveness{false };
30+ };
3731
38- /* *
39- * If `ignoreLiveness` is set, then reachability from the roots is
40- * ignored (dangerous!). However, the paths must still be
41- * unreferenced *within* the store (i.e., there can be no other
42- * store paths that depend on them).
43- */
44- bool ignoreLiveness{false };
32+ /* Garbage collection action: either return paths, or delete them */
33+ using GCAction = std::variant<GCReturn, GCDelete>;
4534
46- /* *
47- * For `gcDeleteSpecific`, the paths to delete.
48- */
49- StorePathSet pathsToDelete;
50-
51- /* *
52- * Stop after at least `maxFreed` bytes have been freed.
53- */
54- uint64_t maxFreed{std::numeric_limits<uint64_t >::max ()};
35+ struct GCOptions {
36+ GCAction action;
37+ /* Stop after at least `maxFreed' bytes have been freed. */
38+ uint64_t maxFreed{std::numeric_limits<uint64_t >::max ()};
5539};
5640
57-
5841struct GCResults
5942{
6043 /* *
@@ -63,10 +46,7 @@ struct GCResults
6346 */
6447 PathSet paths;
6548
66- /* *
67- * For `gcReturnDead`, `gcDeleteDead` and `gcDeleteSpecific`, the
68- * number of bytes that would be or was freed.
69- */
49+ /* For `GCDelete', the number of bytes that would be or was freed. */
7050 uint64_t bytesFreed = 0 ;
7151};
7252
0 commit comments