mirror of
https://github.com/NixOS/nix
synced 2024-09-19 10:50:24 -04:00
Use --keep-going
to make the garbage collector continue when an error occurs
Currently, when an error occurs during garbage collection, the process is aborted and the error is reported. This is not ideal, as it means that the garbage collection is not completed and garbage will continue to be accumulated. Example: ``` error: cannot delete path '/nix/store/4haq90hy2jz3i9n359zpw3bfan9jm0ss-glib-networking-2.78.0' because it is in use by '/nix/store/94nz5lnlsi4ss53izwg1ikifk4bxrs6g-seahorse-43.0', '/nix/store/mfw6k5a1712zqd6q2h4h3ipmx3q0lb1n-geoclue-2.7.0' ``` In this commit, we reuse the existing option `--keep-going` to allow the garbage collection to continue when an error occurs. Co-authored-by: Ramses <ramses@well-founded.dev>
This commit is contained in:
parent
57d9d0d6e4
commit
444f32d0ff
|
@ -4,7 +4,7 @@
|
|||
|
||||
# Synopsis
|
||||
|
||||
`nix-collect-garbage` [`--delete-old`] [`-d`] [`--delete-older-than` *period*] [`--max-freed` *bytes*] [`--dry-run`]
|
||||
`nix-collect-garbage` [`--delete-old`] [`-d`] [`--delete-older-than` *period*] [`--max-freed` *bytes*] [`--dry-run`] [`--keep-going`]
|
||||
|
||||
# Description
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
# Synopsis
|
||||
|
||||
`nix-store` `--gc` [`--print-roots` | `--print-live` | `--print-dead`] [`--max-freed` *bytes*]
|
||||
`nix-store` `--gc` [`--print-roots` | `--print-live` | `--print-dead`] [`--max-freed` *bytes*] [`--keep-going`]
|
||||
|
||||
# Description
|
||||
|
||||
|
|
|
@ -118,6 +118,7 @@ Most Nix commands accept the following command-line options:
|
|||
Keep going in case of failed builds, to the greatest extent possible.
|
||||
That is, if building an input of some derivation fails, Nix will still build the other inputs, but not the derivation itself.
|
||||
Without this option, Nix stops if any build fails (except for builds of substitutes), possibly killing builds in progress (in case of parallel or distributed builds).
|
||||
In the context of garbage collection, this option indicates that the garbage collector should continue deleting garbage even if an error occurs while deleting a path.
|
||||
|
||||
- <span id="opt-keep-failed">[`--keep-failed`](#opt-keep-failed)</span> / `-K`
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "derivations.hh"
|
||||
#include "globals.hh"
|
||||
#include "local-store.hh"
|
||||
#include "posix-fs-canonicalise.hh"
|
||||
#include "finally.hh"
|
||||
#include "unix-domain-socket.hh"
|
||||
#include "signals.hh"
|
||||
|
@ -781,9 +782,19 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
|
|||
for (auto & path : topoSortPaths(visited)) {
|
||||
if (!dead.insert(path).second) continue;
|
||||
if (shouldDelete) {
|
||||
try {
|
||||
invalidatePathChecked(path);
|
||||
deleteFromStore(path.to_string());
|
||||
referrersCache.erase(path);
|
||||
} catch (PathInUse & e) {
|
||||
if (settings.keepGoing) {
|
||||
printError("warning: %s"
|
||||
"Ignoring as `--keep-going` is used.",
|
||||
e.msg());
|
||||
} else {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -14,6 +14,12 @@ R""(
|
|||
# nix store gc --max 1G
|
||||
```
|
||||
|
||||
* Keep deleting garbage even if an error occurs while deleting a path:
|
||||
|
||||
```console
|
||||
# nix store gc --keep-going
|
||||
```
|
||||
|
||||
# Description
|
||||
|
||||
This command deletes unreachable paths in the Nix store.
|
||||
|
|
Loading…
Reference in a new issue