From 6ab3b86cf5d0875920555a41326afc6e5aa752d3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 1 Jun 2022 14:20:38 +0200 Subject: [PATCH] Return narHash when available --- src/libfetchers/fetchers.cc | 15 +++++++++++---- src/libfetchers/fetchers.hh | 4 ++++ src/libfetchers/tarball.cc | 3 ++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/libfetchers/fetchers.cc b/src/libfetchers/fetchers.cc index 5cb0dac17..cce4193ea 100644 --- a/src/libfetchers/fetchers.cc +++ b/src/libfetchers/fetchers.cc @@ -144,13 +144,20 @@ std::pair Input::fetch(ref store) const .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)); if (auto prevNarHash = getNarHash()) { if (narHash != *prevNarHash) 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()) { @@ -168,8 +175,6 @@ std::pair Input::fetch(ref store) const input.locked = true; assert(input.hasAllInfo()); - - return {std::move(tree), input}; } std::pair, Input> Input::lazyFetch(ref store) const @@ -328,6 +333,8 @@ std::pair, Input> InputScheme::lazyFetch(ref store, co { auto [storePath, input2] = fetch(store, input); + input.checkLocked(*store, storePath, input2); + return {makeFSInputAccessor(CanonPath(store->toRealPath(storePath))), input2}; } diff --git a/src/libfetchers/fetchers.hh b/src/libfetchers/fetchers.hh index 6ca798b71..cc53e76b8 100644 --- a/src/libfetchers/fetchers.hh +++ b/src/libfetchers/fetchers.hh @@ -101,6 +101,10 @@ public: std::optional getRev() const; std::optional getRevCount() const; std::optional getLastModified() const; + +private: + + void checkLocked(Store & store, const StorePath & storePath, Input & input) const; }; /* The InputScheme represents a type of fetcher. Each fetcher diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc index 6c551bd93..9489b9ca9 100644 --- a/src/libfetchers/tarball.cc +++ b/src/libfetchers/tarball.cc @@ -223,7 +223,8 @@ struct CurlInputScheme : InputScheme ParsedURL toURL(const Input & input) override { 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()) url.query.insert_or_assign("narHash", narHash->to_string(SRI, true)); return url;