* `nix-store --verify': repair bad referer mappings.

This commit is contained in:
Eelco Dolstra 2005-03-25 14:21:49 +00:00
parent c6178f0b03
commit 7eaf038763

View file

@ -774,7 +774,7 @@ void verifyStore(bool checkContents)
if (usablePaths.find(*i) == usablePaths.end()) { if (usablePaths.find(*i) == usablePaths.end()) {
printMsg(lvlError, format("found references entry for unusable path `%1%'") printMsg(lvlError, format("found references entry for unusable path `%1%'")
% *i); % *i);
nixDB.delPair(txn, dbReferences, *i); setReferences(txn, *i, PathSet());
} }
else { else {
bool isValid = validPaths.find(*i) != validPaths.end(); bool isValid = validPaths.find(*i) != validPaths.end();
@ -808,18 +808,28 @@ void verifyStore(bool checkContents)
nixDB.delPair(txn, dbReferers, *i); nixDB.delPair(txn, dbReferers, *i);
} }
else { else {
PathSet referers; PathSet referers, newReferers;
queryReferers(txn, *i, referers); queryReferers(txn, *i, referers);
for (PathSet::iterator j = referers.begin(); for (PathSet::iterator j = referers.begin();
j != referers.end(); ++j) j != referers.end(); ++j)
{ {
Paths references; Paths references;
nixDB.queryStrings(txn, dbReferences, *j, references); if (usablePaths.find(*j) == usablePaths.end()) {
if (find(references.begin(), references.end(), *i) == references.end()) { printMsg(lvlError, format("referer mapping from `%1%' to unusable `%2%'")
printMsg(lvlError, format("missing reference mapping from `%1%' to `%2%'") % *i % *j);
% *j % *i); } else {
nixDB.queryStrings(txn, dbReferences, *j, references);
if (find(references.begin(), references.end(), *i) == references.end()) {
printMsg(lvlError, format("missing reference mapping from `%1%' to `%2%'")
% *j % *i);
/* !!! repair by inserting *i into references */
}
else newReferers.insert(*j);
} }
} }
if (referers != newReferers)
nixDB.setStrings(txn, dbReferers, *i,
Paths(newReferers.begin(), newReferers.end()));
} }
} }