1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-19 23:03:53 -04:00

Make verifyAllValidPaths more functional

return map rather than mutate one passed in by reference
This commit is contained in:
John Ericson 2023-08-02 14:38:22 -04:00
parent 73c9fc7ab1
commit 6b297e5895
4 changed files with 19 additions and 12 deletions

View file

@ -243,19 +243,21 @@ void LocalOverlayStore::optimiseStore()
}
bool LocalOverlayStore::verifyAllValidPaths(RepairFlag repair, StorePathSet & validPaths)
std::pair<bool, StorePathSet> LocalOverlayStore::verifyAllValidPaths(RepairFlag repair)
{
StorePathSet done;
bool errors = false;
auto existsInStoreDir = [&](const StorePath & storePath) {
return pathExists(realStoreDir.get() + "/" + storePath.to_string());
};
bool errors = false;
StorePathSet validPaths;
for (auto & i : queryAllValidPaths())
verifyPath(i, existsInStoreDir, done, validPaths, repair, errors);
return errors;
return { errors, validPaths };
}

View file

@ -139,7 +139,7 @@ private:
* We don't verify the contents of both layers on the assumption that the lower layer is far bigger,
* and also the observation that anything not in the upper db the overlayfs doesn't yet care about.
*/
bool verifyAllValidPaths(RepairFlag repair, StorePathSet & validPaths) override;
std::pair<bool, StorePathSet> verifyAllValidPaths(RepairFlag repair) override;
/**
* For lower-store paths, we used the lower store location. This avoids the

View file

@ -1503,9 +1503,7 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair)
auto fdGCLock = openGCLock();
FdLock gcLock(fdGCLock.get(), ltRead, true, "waiting for the big garbage collector lock...");
StorePathSet validPaths;
bool errors = verifyAllValidPaths(repair, validPaths);
auto [errors, validPaths] = verifyAllValidPaths(repair);
/* Optionally, check the content hashes (slow). */
if (checkContents) {
@ -1591,7 +1589,7 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair)
}
bool LocalStore::verifyAllValidPaths(RepairFlag repair, StorePathSet & validPaths)
std::pair<bool, StorePathSet> LocalStore::verifyAllValidPaths(RepairFlag repair)
{
StorePathSet storePathsInStoreDir;
/* Why aren't we using `queryAllValidPaths`? Because that would
@ -1613,16 +1611,18 @@ bool LocalStore::verifyAllValidPaths(RepairFlag repair, StorePathSet & validPath
printInfo("checking path existence...");
StorePathSet done;
bool errors = false;
auto existsInStoreDir = [&](const StorePath & storePath) {
return storePathsInStoreDir.count(storePath);
};
bool errors = false;
StorePathSet validPaths;
for (auto & i : queryAllValidPaths())
verifyPath(i, existsInStoreDir, done, validPaths, repair, errors);
return errors;
return { errors, validPaths };
}

View file

@ -265,7 +265,12 @@ public:
bool verifyStore(bool checkContents, RepairFlag repair) override;
virtual bool verifyAllValidPaths(RepairFlag repair, StorePathSet & validPaths);
/**
* @return A pair of whether any errors were encountered, and a set of
* (so-far) valid paths. The store objects pointed to by those paths are
* suitable for further validation checking.
*/
virtual std::pair<bool, StorePathSet> verifyAllValidPaths(RepairFlag repair);
/**
* Register the validity of a path, i.e., that `path` exists, that