Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make nix-store --delete explain why a path is alive #4850

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/libstore/gc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ bool LocalStore::canReachRoot(GCState & state, StorePathSet & visited, const Sto
if (state.dead.count(path)) return false;

if (state.roots.count(path)) {
debug("cannot delete '%1%' because it's a root", printStorePath(path));
printInfo("need '%1%' because it's a root", printStorePath(path));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with what @roberth said.

Let's return something like:

struct DeadAlready {};
struct IsRoot {};
struct RootedBy { StorePath root; };

typedef std::variant<DeadAlready, IsRoot, RootedBy> OptLiveness;

to indicate why.

state.alive can likewise be a map of:

typedef std::variant<IsRoot, RootedBy> Liveness;

Making OptLiveness be std::optional<Liveness> is fine me too.

state.alive.insert(path);
return true;
}
Expand Down Expand Up @@ -594,6 +594,7 @@ bool LocalStore::canReachRoot(GCState & state, StorePathSet & visited, const Sto
for (auto & i : incoming)
if (i != path)
if (canReachRoot(state, visited, i)) {
printInfo("need '%1%' for '%2%'", printStorePath(path), printStorePath(i));
state.alive.insert(path);
return true;
}
Expand Down Expand Up @@ -760,9 +761,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
tryToDelete(state, printStorePath(i));
if (state.dead.find(i) == state.dead.end())
throw Error(
"cannot delete path '%1%' since it is still alive. "
"To find out why use: "
"nix-store --query --roots",
"cannot delete path '%1%' since it is still alive",
printStorePath(i));
}

Expand Down