Subject: Re: bug#51427: [PATCH] nix: libstore: Do not remove unused links when deleting specific items.

From: Ludovic Courtès <[email-masked]>
Date: Thu, 28 Oct 2021 16:16:22 +0200

Hi,

Maxim Cournoyer <[email-masked]> skribis:

> Deleting unused links can be a very costly operation, especially on rotative
> hard drives.  As removing single store items is often used for experimentation
> rather than for cleaning purposes, this change allows it to run without the
> links cleanup.
>
> * nix/libstore/gc.cc (LocalStore::collectGarbage): Do not clean up links when
> the specified action is GCOptions::gcDeleteSpecific.
> ---
>  nix/libstore/gc.cc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/nix/libstore/gc.cc b/nix/libstore/gc.cc
> index e1d0765154..7d872d8cc1 100644
> --- a/nix/libstore/gc.cc
> +++ b/nix/libstore/gc.cc
> @@ -771,7 +771,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
>      deleteGarbage(state, state.trashDir);
>  
>      /* Clean up the links directory. */
> -    if (options.action == GCOptions::gcDeleteDead || options.action == GCOptions::gcDeleteSpecific) {
> +    if (options.action == GCOptions::gcDeleteDead) {

I believe the effect is that ‘guix gc -D /gnu/store/…-disk-image’ would
remove nothing: /gnu/store/.links would still contain a copy of that big
disk image, so as a result, you’ve freed zero bytes.

Am I right?

Perhaps what we could do is, upon ‘gcDeleteSpecific’, only look at the
relevant entry in .links instead of traversing all of them.

WDYT?

Thanks,
Ludo’.