libstore/profiles: do not dereference current generation if it doesn't exist
If the profile inode is invalid, e.g. invalid symlink, the current generation cannot be discovered. Nonetheless, this should not be a reason for an assert failure, instead of crashing, just raise an error. Fixes fj#801. Change-Id: I63937672173bc3bf37196de98307800adc5757e1 Signed-off-by: Raito Bezarius <raito@lix.systems> Co-authored-by: Qyriad <qyriad@qyriad.me>
This commit is contained in:
@@ -153,8 +153,11 @@ void deleteGenerations(
|
||||
|
||||
auto [gens, curGen] = findGenerations(profile);
|
||||
|
||||
if (!curGen)
|
||||
throw Error("cannot find current generation of profile '%1%', is it a valid symlink?", profile);
|
||||
|
||||
if (gensToDelete.count(*curGen))
|
||||
throw Error("cannot delete current version of profile %1%'", profile);
|
||||
throw Error("cannot delete current version of profile '%1%'", profile);
|
||||
|
||||
for (auto & i : gens) {
|
||||
if (!gensToDelete.count(i.number)) continue;
|
||||
|
||||
@@ -68,6 +68,11 @@ clearProfiles() {
|
||||
rm -rf "$profiles"
|
||||
}
|
||||
|
||||
linkProfilesTo() {
|
||||
target="$1"
|
||||
ln -s "$HOME"/.local/state/nix/profiles "$target"
|
||||
}
|
||||
|
||||
clearStore() {
|
||||
echo "clearing store..."
|
||||
chmod -R +w "$NIX_STORE_DIR"
|
||||
|
||||
@@ -4,6 +4,13 @@ if [ -z "${storeCleared-}" ]; then
|
||||
clearStore
|
||||
fi
|
||||
|
||||
# Test if invalid profiles symlinks are supported.
|
||||
# https://git.lix.systems/lix-project/lix/issues/801
|
||||
VOID=$(mktemp -d)
|
||||
rm -rf "$VOID"
|
||||
linkProfilesTo $VOID
|
||||
expectStderr 1 nix-env --delete-generations 0 | grepQuiet -E "error: cannot find current generation of profile '.*local/state/nix/profiles/profile', is it a valid symlink?"
|
||||
|
||||
clearProfiles
|
||||
|
||||
# Query installed: should be empty.
|
||||
|
||||
Reference in New Issue
Block a user