diff --git a/src/libstore/gc-store.hh b/src/libstore/gc-store.hh index 2c26c65c4..da1551056 100644 --- a/src/libstore/gc-store.hh +++ b/src/libstore/gc-store.hh @@ -97,6 +97,13 @@ struct GcStore : public virtual Store * Perform a garbage collection. */ virtual void collectGarbage(const GCOptions & options, GCResults & results) = 0; + + /** + * Called by `collectGarbage` to recursively delete a path. + * The default implementation simply calls `deletePath`, but it can be + * overridden by stores that wish to provide their own deletion behaviour. + */ + virtual void deleteGCPath(const Path & path, uint64_t & bytesFreed); }; } diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index 3c9544017..959f4d3b1 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -654,7 +654,8 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) results.paths.insert(path); uint64_t bytesFreed; - deletePath(realPath, bytesFreed); + deleteGCPath(realPath, bytesFreed); + results.bytesFreed += bytesFreed; if (results.bytesFreed > options.maxFreed) { @@ -872,7 +873,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) if (unlink(path.c_str()) == -1) throw SysError("deleting '%1%'", path); - /* Do not accound for deleted file here. Rely on deletePath() + /* Do not account for deleted file here. Rely on deletePath() accounting. */ } @@ -890,6 +891,12 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) } +void GcStore::deleteGCPath(const Path & path, uint64_t & bytesFreed) +{ + deletePath(path, bytesFreed); +} + + void LocalStore::autoGC(bool sync) { static auto fakeFreeSpaceFile = getEnv("_NIX_TEST_FREE_SPACE_FILE");