Move hash into SourceInfo and rename to narHash to avoid ambiguity

This commit is contained in:
Eelco Dolstra 2019-05-28 13:07:15 +02:00
parent 6d7efcfaeb
commit 894e007445
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
2 changed files with 8 additions and 10 deletions

View file

@ -263,6 +263,7 @@ static SourceInfo fetchFlake(EvalState & state, const FlakeRef & flakeRef, bool
ref.rev = Hash(std::string(*result.etag, 1, result.etag->size() - 2), htSHA1); ref.rev = Hash(std::string(*result.etag, 1, result.etag->size() - 2), htSHA1);
SourceInfo info(ref); SourceInfo info(ref);
info.storePath = result.storePath; info.storePath = result.storePath;
info.narHash = state.store->queryPathInfo(info.storePath)->narHash;
return info; return info;
} }
@ -276,6 +277,7 @@ static SourceInfo fetchFlake(EvalState & state, const FlakeRef & flakeRef, bool
SourceInfo info(ref); SourceInfo info(ref);
info.storePath = gitInfo.storePath; info.storePath = gitInfo.storePath;
info.revCount = gitInfo.revCount; info.revCount = gitInfo.revCount;
info.narHash = state.store->queryPathInfo(info.storePath)->narHash;
return info; return info;
} }
@ -289,6 +291,7 @@ static SourceInfo fetchFlake(EvalState & state, const FlakeRef & flakeRef, bool
SourceInfo info(ref); SourceInfo info(ref);
info.storePath = gitInfo.storePath; info.storePath = gitInfo.storePath;
info.revCount = gitInfo.revCount; info.revCount = gitInfo.revCount;
info.narHash = state.store->queryPathInfo(info.storePath)->narHash;
return info; return info;
} }
@ -315,7 +318,6 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool impureIsAllowe
throw Error("'flake.nix' file of flake '%s' escapes from '%s'", resolvedRef, sourceInfo.storePath); throw Error("'flake.nix' file of flake '%s' escapes from '%s'", resolvedRef, sourceInfo.storePath);
Flake flake(flakeRef, sourceInfo); Flake flake(flakeRef, sourceInfo);
flake.hash = state.store->queryPathInfo(sourceInfo.storePath)->narHash;
if (!pathExists(realFlakeFile)) if (!pathExists(realFlakeFile))
throw Error("source tree referenced by '%s' does not contain a '%s/flake.nix' file", resolvedRef, resolvedRef.subdir); throw Error("source tree referenced by '%s' does not contain a '%s/flake.nix' file", resolvedRef, resolvedRef.subdir);
@ -380,8 +382,6 @@ NonFlake getNonFlake(EvalState & state, const FlakeRef & flakeRef, FlakeAlias al
if (state.allowedPaths) if (state.allowedPaths)
state.allowedPaths->insert(nonFlake.sourceInfo.storePath); state.allowedPaths->insert(nonFlake.sourceInfo.storePath);
nonFlake.hash = state.store->queryPathInfo(nonFlake.sourceInfo.storePath)->narHash;
nonFlake.alias = alias; nonFlake.alias = alias;
return nonFlake; return nonFlake;
@ -397,13 +397,13 @@ LockFile entryToLockFile(const LockFile::FlakeEntry & entry)
LockFile::FlakeEntry dependenciesToFlakeEntry(const ResolvedFlake & resolvedFlake) LockFile::FlakeEntry dependenciesToFlakeEntry(const ResolvedFlake & resolvedFlake)
{ {
LockFile::FlakeEntry entry(resolvedFlake.flake.resolvedRef, resolvedFlake.flake.hash); LockFile::FlakeEntry entry(resolvedFlake.flake.resolvedRef, resolvedFlake.flake.sourceInfo.narHash);
for (auto & info : resolvedFlake.flakeDeps) for (auto & info : resolvedFlake.flakeDeps)
entry.flakeEntries.insert_or_assign(info.first.to_string(), dependenciesToFlakeEntry(info.second)); entry.flakeEntries.insert_or_assign(info.first.to_string(), dependenciesToFlakeEntry(info.second));
for (auto & nonFlake : resolvedFlake.nonFlakeDeps) { for (auto & nonFlake : resolvedFlake.nonFlakeDeps) {
LockFile::NonFlakeEntry nonEntry(nonFlake.resolvedRef, nonFlake.hash); LockFile::NonFlakeEntry nonEntry(nonFlake.resolvedRef, nonFlake.sourceInfo.narHash);
entry.nonFlakeEntries.insert_or_assign(nonFlake.alias, nonEntry); entry.nonFlakeEntries.insert_or_assign(nonFlake.alias, nonEntry);
} }
@ -443,7 +443,7 @@ ResolvedFlake resolveFlakeFromLockFile(EvalState & state, const FlakeRef & flake
auto i = lockFile.nonFlakeEntries.find(nonFlakeInfo.first); auto i = lockFile.nonFlakeEntries.find(nonFlakeInfo.first);
if (i != lockFile.nonFlakeEntries.end()) { if (i != lockFile.nonFlakeEntries.end()) {
NonFlake nonFlake = getNonFlake(state, i->second.ref, nonFlakeInfo.first); NonFlake nonFlake = getNonFlake(state, i->second.ref, nonFlakeInfo.first);
if (nonFlake.hash != i->second.contentHash) if (nonFlake.sourceInfo.narHash != i->second.contentHash)
throw Error("the content hash of flakeref '%s' doesn't match", i->second.ref.to_string()); throw Error("the content hash of flakeref '%s' doesn't match", i->second.ref.to_string());
deps.nonFlakeDeps.push_back(nonFlake); deps.nonFlakeDeps.push_back(nonFlake);
} else { } else {
@ -457,7 +457,7 @@ ResolvedFlake resolveFlakeFromLockFile(EvalState & state, const FlakeRef & flake
auto i = lockFile.flakeEntries.find(newFlakeRef); auto i = lockFile.flakeEntries.find(newFlakeRef);
if (i != lockFile.flakeEntries.end()) { // Propagate lockFile downwards if possible if (i != lockFile.flakeEntries.end()) { // Propagate lockFile downwards if possible
ResolvedFlake newResFlake = resolveFlakeFromLockFile(state, i->second.ref, handleLockFile, entryToLockFile(i->second)); ResolvedFlake newResFlake = resolveFlakeFromLockFile(state, i->second.ref, handleLockFile, entryToLockFile(i->second));
if (newResFlake.flake.hash != i->second.contentHash) if (newResFlake.flake.sourceInfo.narHash != i->second.contentHash)
throw Error("the content hash of flakeref '%s' doesn't match", i->second.ref.to_string()); throw Error("the content hash of flakeref '%s' doesn't match", i->second.ref.to_string());
deps.flakeDeps.insert_or_assign(newFlakeRef, newResFlake); deps.flakeDeps.insert_or_assign(newFlakeRef, newResFlake);
} else { } else {

View file

@ -84,7 +84,7 @@ struct SourceInfo
FlakeRef resolvedRef; FlakeRef resolvedRef;
Path storePath; Path storePath;
std::optional<uint64_t> revCount; std::optional<uint64_t> revCount;
// date Hash narHash; // store path hash
SourceInfo(const FlakeRef & resolvRef) : resolvedRef(resolvRef) {}; SourceInfo(const FlakeRef & resolvRef) : resolvedRef(resolvRef) {};
}; };
@ -95,7 +95,6 @@ struct Flake
FlakeRef resolvedRef; FlakeRef resolvedRef;
std::string description; std::string description;
SourceInfo sourceInfo; SourceInfo sourceInfo;
Hash hash; // content hash
std::vector<FlakeRef> requires; std::vector<FlakeRef> requires;
std::map<FlakeAlias, FlakeRef> nonFlakeRequires; std::map<FlakeAlias, FlakeRef> nonFlakeRequires;
Value * vProvides; // FIXME: gc Value * vProvides; // FIXME: gc
@ -111,7 +110,6 @@ struct NonFlake
FlakeRef originalRef; FlakeRef originalRef;
FlakeRef resolvedRef; FlakeRef resolvedRef;
SourceInfo sourceInfo; SourceInfo sourceInfo;
Hash hash;
NonFlake(const FlakeRef & origRef, const SourceInfo & sourceInfo) : NonFlake(const FlakeRef & origRef, const SourceInfo & sourceInfo) :
originalRef(origRef), resolvedRef(sourceInfo.resolvedRef), sourceInfo(sourceInfo) {}; originalRef(origRef), resolvedRef(sourceInfo.resolvedRef), sourceInfo(sourceInfo) {};
}; };