Skip to content

Commit

Permalink
Merge pull request #8754 from NixLayeredStore/refactor-store-verify
Browse files Browse the repository at this point in the history
Refactor `verifyPath` to take `StorePath` instead of `Path`
  • Loading branch information
Ericson2314 authored Jul 31, 2023
2 parents c0e735f + c9a87ce commit dcdd5fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
21 changes: 8 additions & 13 deletions src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1506,10 +1506,10 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair)
printInfo("checking path existence...");

StorePathSet validPaths;
PathSet done;
StorePathSet done;

for (auto & i : queryAllValidPaths())
verifyPath(printStorePath(i), store, done, validPaths, repair, errors);
verifyPath(i, store, done, validPaths, repair, errors);

/* Optionally, check the content hashes (slow). */
if (checkContents) {
Expand Down Expand Up @@ -1595,19 +1595,12 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair)
}


void LocalStore::verifyPath(const Path & pathS, const StringSet & store,
PathSet & done, StorePathSet & validPaths, RepairFlag repair, bool & errors)
void LocalStore::verifyPath(const StorePath & path, const StringSet & store,
StorePathSet & done, StorePathSet & validPaths, RepairFlag repair, bool & errors)
{
checkInterrupt();

if (!done.insert(pathS).second) return;

if (!isStorePath(pathS)) {
printError("path '%s' is not in the Nix store", pathS);
return;
}

auto path = parseStorePath(pathS);
if (!done.insert(path).second) return;

if (!store.count(std::string(path.to_string()))) {
/* Check any referrers first. If we can invalidate them
Expand All @@ -1616,11 +1609,13 @@ void LocalStore::verifyPath(const Path & pathS, const StringSet & store,
StorePathSet referrers; queryReferrers(path, referrers);
for (auto & i : referrers)
if (i != path) {
verifyPath(printStorePath(i), store, done, validPaths, repair, errors);
verifyPath(i, store, done, validPaths, repair, errors);
if (validPaths.count(i))
canInvalidate = false;
}

auto pathS = printStorePath(path);

if (canInvalidate) {
printInfo("path '%s' disappeared, removing from database...", pathS);
auto state(_state.lock());
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/local-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ private:
*/
void invalidatePathChecked(const StorePath & path);

void verifyPath(const Path & path, const StringSet & store,
PathSet & done, StorePathSet & validPaths, RepairFlag repair, bool & errors);
void verifyPath(const StorePath & path, const StringSet & store,
StorePathSet & done, StorePathSet & validPaths, RepairFlag repair, bool & errors);

std::shared_ptr<const ValidPathInfo> queryPathInfoInternal(State & state, const StorePath & path);

Expand Down

0 comments on commit dcdd5fe

Please sign in to comment.