aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/gc-store.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2022-03-01 18:31:36 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2022-03-03 19:01:25 +0000
commit6636202356b94ca4128462493770e7fedf997b0e (patch)
tree94425988649343830763bacb1b3a5bdf4fcff1df /src/libstore/gc-store.cc
parent391f4fcabe6c307afeb2f39dec07d43f1e6bf748 (diff)
Factor out a `GcStore` interface
Starts progress on #5729. The idea is that we should not have these default methods throwing "unimplemented". This is a small step in that direction. I kept `addTempRoot` because it is a no-op, rather than failure. Also, as a practical matter, it is called all over the place, while doing other tasks, so the downcasting would be annoying. Maybe in the future I could move the "real" `addTempRoot` to `GcStore`, and the existing usecases use a `tryAddTempRoot` wrapper to downcast or do nothing, but I wasn't sure whether that was a good idea so with a bias to less churn I didn't do it yet.
Diffstat (limited to 'src/libstore/gc-store.cc')
-rw-r--r--src/libstore/gc-store.cc13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libstore/gc-store.cc b/src/libstore/gc-store.cc
new file mode 100644
index 000000000..3dbdec53b
--- /dev/null
+++ b/src/libstore/gc-store.cc
@@ -0,0 +1,13 @@
+#include "gc-store.hh"
+
+namespace nix {
+
+GcStore & requireGcStore(Store & store)
+{
+ auto * gcStore = dynamic_cast<GcStore *>(&store);
+ if (!gcStore)
+ throw UsageError("Garbage collection not supported by this store");
+ return *gcStore;
+}
+
+}