mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-24 14:56:15 +02:00
Return narHash when available
This commit is contained in:
parent
b01ee2a93d
commit
6ab3b86cf5
3 changed files with 17 additions and 5 deletions
|
@ -144,13 +144,20 @@ std::pair<Tree, Input> Input::fetch(ref<Store> store) const
|
||||||
.storePath = storePath,
|
.storePath = storePath,
|
||||||
};
|
};
|
||||||
|
|
||||||
auto narHash = store->queryPathInfo(tree.storePath)->narHash;
|
checkLocked(*store, storePath, input);
|
||||||
|
|
||||||
|
return {std::move(tree), input};
|
||||||
|
}
|
||||||
|
|
||||||
|
void Input::checkLocked(Store & store, const StorePath & storePath, Input & input) const
|
||||||
|
{
|
||||||
|
auto narHash = store.queryPathInfo(storePath)->narHash;
|
||||||
input.attrs.insert_or_assign("narHash", narHash.to_string(SRI, true));
|
input.attrs.insert_or_assign("narHash", narHash.to_string(SRI, true));
|
||||||
|
|
||||||
if (auto prevNarHash = getNarHash()) {
|
if (auto prevNarHash = getNarHash()) {
|
||||||
if (narHash != *prevNarHash)
|
if (narHash != *prevNarHash)
|
||||||
throw Error((unsigned int) 102, "NAR hash mismatch in input '%s' (%s), expected '%s', got '%s'",
|
throw Error((unsigned int) 102, "NAR hash mismatch in input '%s' (%s), expected '%s', got '%s'",
|
||||||
to_string(), tree.actualPath, prevNarHash->to_string(SRI, true), narHash.to_string(SRI, true));
|
to_string(), store.printStorePath(storePath), prevNarHash->to_string(SRI, true), narHash.to_string(SRI, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto prevLastModified = getLastModified()) {
|
if (auto prevLastModified = getLastModified()) {
|
||||||
|
@ -168,8 +175,6 @@ std::pair<Tree, Input> Input::fetch(ref<Store> store) const
|
||||||
input.locked = true;
|
input.locked = true;
|
||||||
|
|
||||||
assert(input.hasAllInfo());
|
assert(input.hasAllInfo());
|
||||||
|
|
||||||
return {std::move(tree), input};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<ref<InputAccessor>, Input> Input::lazyFetch(ref<Store> store) const
|
std::pair<ref<InputAccessor>, Input> Input::lazyFetch(ref<Store> store) const
|
||||||
|
@ -328,6 +333,8 @@ std::pair<ref<InputAccessor>, Input> InputScheme::lazyFetch(ref<Store> store, co
|
||||||
{
|
{
|
||||||
auto [storePath, input2] = fetch(store, input);
|
auto [storePath, input2] = fetch(store, input);
|
||||||
|
|
||||||
|
input.checkLocked(*store, storePath, input2);
|
||||||
|
|
||||||
return {makeFSInputAccessor(CanonPath(store->toRealPath(storePath))), input2};
|
return {makeFSInputAccessor(CanonPath(store->toRealPath(storePath))), input2};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,10 @@ public:
|
||||||
std::optional<Hash> getRev() const;
|
std::optional<Hash> getRev() const;
|
||||||
std::optional<uint64_t> getRevCount() const;
|
std::optional<uint64_t> getRevCount() const;
|
||||||
std::optional<time_t> getLastModified() const;
|
std::optional<time_t> getLastModified() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void checkLocked(Store & store, const StorePath & storePath, Input & input) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* The InputScheme represents a type of fetcher. Each fetcher
|
/* The InputScheme represents a type of fetcher. Each fetcher
|
||||||
|
|
|
@ -223,7 +223,8 @@ struct CurlInputScheme : InputScheme
|
||||||
ParsedURL toURL(const Input & input) override
|
ParsedURL toURL(const Input & input) override
|
||||||
{
|
{
|
||||||
auto url = parseURL(getStrAttr(input.attrs, "url"));
|
auto url = parseURL(getStrAttr(input.attrs, "url"));
|
||||||
// NAR hashes are preferred over file hashes since tar/zip files // don't have a canonical representation.
|
// NAR hashes are preferred over file hashes since tar/zip
|
||||||
|
// files don't have a canonical representation.
|
||||||
if (auto narHash = input.getNarHash())
|
if (auto narHash = input.getNarHash())
|
||||||
url.query.insert_or_assign("narHash", narHash->to_string(SRI, true));
|
url.query.insert_or_assign("narHash", narHash->to_string(SRI, true));
|
||||||
return url;
|
return url;
|
||||||
|
|
Loading…
Reference in a new issue