From 0d0f7b84946396b767b9c3a0941761334b7e871f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= Date: Tue, 3 Jan 2023 13:37:49 +0100 Subject: [PATCH] POC: Make `nix store delete --recursive` best effort Only delete the free paths in the closure rather than trying to delete everything. --- src/libstore/gc.cc | 4 ++-- src/nix/store-delete.cc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index 20720fb99ab6..efa725283d3c 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -783,11 +783,11 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) /* Either delete all garbage paths, or just the specified paths (for gcDeleteSpecific). */ - if (options.action == GCOptions::gcDeleteSpecific) { + if (options.action == GCOptions::gcDeleteSpecific || options.action == GCOptions::gcDeleteDead) { for (auto & i : options.pathsToDelete) { deleteReferrersClosure(i); - if (!dead.count(i)) + if (options.action == GCOptions::gcDeleteSpecific && !dead.count(i)) throw Error( "Cannot delete path '%1%' since it is still alive. " "To find out why, use: " diff --git a/src/nix/store-delete.cc b/src/nix/store-delete.cc index 6719227dfe70..922cc699fc2a 100644 --- a/src/nix/store-delete.cc +++ b/src/nix/store-delete.cc @@ -9,7 +9,7 @@ using namespace nix; struct CmdStoreDelete : StorePathsCommand { - GCOptions options { .action = GCOptions::gcDeleteSpecific }; + GCOptions options { .action = GCOptions::gcDeleteDead }; CmdStoreDelete() {