Skip to content

Commit

Permalink
Remove Hash::operator bool ()
Browse files Browse the repository at this point in the history
Since the hash is not optional anymore
  • Loading branch information
meditans committed Aug 5, 2020
1 parent be6e1c6 commit 8241e66
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/libstore/binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ struct FileSource : FdSource
void BinaryCacheStore::addToStore(const ValidPathInfo & info, Source & narSource,
RepairFlag repair, CheckSigsFlag checkSigs)
{
assert(info.narHash && info.narSize);
assert(info.narSize);

if (!repair && isValidPath(info.path)) {
// FIXME: copyNAR -> null sink
Expand Down
5 changes: 1 addition & 4 deletions src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ void LocalStore::registerValidPaths(const ValidPathInfos & infos)
StorePathSet paths;

for (auto & i : infos) {
assert(i.narHash && i.narHash.type == htSHA256);
assert(i.narHash.type == htSHA256);
if (isValidPath_(*state, i.path))
updatePathInfo(*state, i);
else
Expand Down Expand Up @@ -984,9 +984,6 @@ const PublicKeys & LocalStore::getPublicKeys()
void LocalStore::addToStore(const ValidPathInfo & info, Source & source,
RepairFlag repair, CheckSigsFlag checkSigs)
{
if (!info.narHash)
throw Error("cannot add path '%s' because it lacks a hash", printStorePath(info.path));

if (requireSigs && checkSigs && !info.checkSignatures(*this, getPublicKeys()))
throw Error("cannot add path '%s' because it lacks a valid signature", printStorePath(info.path));

Expand Down
4 changes: 2 additions & 2 deletions src/libstore/nar-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ NarInfo::NarInfo(const Store & store, const std::string & s, const std::string &

if (compression == "") compression = "bzip2";

if (!havePath || url.empty() || narSize == 0 || !narHash) throw corrupt();
if (!havePath || url.empty() || narSize == 0) throw corrupt();
}

std::string NarInfo::to_string(const Store & store) const
Expand All @@ -89,7 +89,7 @@ std::string NarInfo::to_string(const Store & store) const
assert(fileHash && fileHash->type == htSHA256);
res += "FileHash: " + fileHash->to_string(Base32, true) + "\n";
res += "FileSize: " + std::to_string(fileSize) + "\n";
assert(narHash && narHash.type == htSHA256);
assert(narHash.type == htSHA256);
res += "NarHash: " + narHash.to_string(Base32, true) + "\n";
res += "NarSize: " + std::to_string(narSize) + "\n";

Expand Down
18 changes: 2 additions & 16 deletions src/libstore/store-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -725,20 +725,6 @@ void copyStorePath(ref<Store> srcStore, ref<Store> dstStore,
info = info2;
}

if (!info->narHash) {
StringSink sink;
srcStore->narFromPath({storePath}, sink);
auto info2 = make_ref<ValidPathInfo>(*info);
info2->narHash = hashString(htSHA256, *sink.s);
if (!info->narSize) info2->narSize = sink.s->size();
if (info->ultimate) info2->ultimate = false;
info = info2;

StringSource source(*sink.s);
dstStore->addToStore(*info, source, repair, checkSigs);
return;
}

if (info->ultimate) {
auto info2 = make_ref<ValidPathInfo>(*info);
info2->ultimate = false;
Expand Down Expand Up @@ -910,8 +896,8 @@ string showPaths(const PathSet & paths)

std::string ValidPathInfo::fingerprint(const Store & store) const
{
if (narSize == 0 || !narHash)
throw Error("cannot calculate fingerprint of path '%s' because its size/hash is not known",
if (narSize == 0)
throw Error("cannot calculate fingerprint of path '%s' because its size is not known",
store.printStorePath(path));
return
"1;" + store.printStorePath(path) + ";"
Expand Down
3 changes: 0 additions & 3 deletions src/libutil/hash.hh
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ private:
Hash(std::string_view s, HashType type, bool isSRI);

public:
/* Check whether a hash is set. */
operator bool () const { return (bool) type; }

/* Check whether two hash are equal. */
bool operator == (const Hash & h2) const;

Expand Down
4 changes: 2 additions & 2 deletions src/nix-store/nix-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
for (auto & j : maybeUseOutputs(store->followLinksToStorePath(i), useOutput, forceRealise)) {
auto info = store->queryPathInfo(j);
if (query == qHash) {
assert(info->narHash && info->narHash.type == htSHA256);
assert(info->narHash.type == htSHA256);
cout << fmt("%s\n", info->narHash.to_string(Base32, true));
} else if (query == qSize)
cout << fmt("%d\n", info->narSize);
Expand Down Expand Up @@ -862,7 +862,7 @@ static void opServe(Strings opFlags, Strings opArgs)
out << info->narSize // downloadSize
<< info->narSize;
if (GET_PROTOCOL_MINOR(clientVersion) >= 4)
out << (info->narHash ? info->narHash.to_string(Base32, true) : "")
out << info->narHash.to_string(Base32, true)
<< renderContentAddress(info->ca)
<< info->sigs;
} catch (InvalidPath &) {
Expand Down

0 comments on commit 8241e66

Please sign in to comment.