This commit is contained in:
Eelco Dolstra 2019-11-26 20:26:22 +01:00
parent 96e1c39bb7
commit ec5e7b44ff
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -1244,30 +1244,24 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair)
printInfo("checking link hashes..."); printInfo("checking link hashes...");
AutoCloseDir dir(opendir(linksDir.c_str())); for (auto & link : readDirectory(linksDir)) {
if (!dir) throw SysError(format("opening directory '%1%'") % linksDir); printMsg(lvlTalkative, "checking contents of '%s'", link.name);
Path linkPath = linksDir + "/" + link.name;
struct dirent * dirent;
while (errno = 0, dirent = readdir(dir.get())) { /* sic */
checkInterrupt();
if (strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name, "..") == 0) continue;
Path linkPath = linksDir + "/" + dirent->d_name;
string hash = hashPath(htSHA256, linkPath).first.to_string(Base32, false); string hash = hashPath(htSHA256, linkPath).first.to_string(Base32, false);
if (hash != dirent->d_name) { if (hash != link.name) {
printError(format("link '%1%' was modified! " printError(
"expected hash '%2%', got '%3%'") "link '%s' was modified! expected hash '%s', got '%s'",
% linkPath % dirent->d_name % hash); linkPath, link.name, hash);
if (repair) { if (repair) {
if (unlink(linkPath.c_str()) == 0) if (unlink(linkPath.c_str()) == 0)
printError(format("Removed link '%1%'") % linkPath); printError("removed link '%s'", linkPath);
else else
throw SysError(format("removing corrupt link '%1%'") % linkPath); throw SysError("removing corrupt link '%s'", linkPath);
} else { } else {
errors = true; errors = true;
} }
} }
} }
if (errno) throw SysError(format("reading directory '%1%'") % linksDir);
printInfo("checking store hashes..."); printInfo("checking store hashes...");