Skip to content

Commit

Permalink
Don't mark inputs as final in getAccessorUnchecked()
Browse files Browse the repository at this point in the history
We haven't added the narHash attribute yet at that point. And if the
caller uses getAccesor() instead of fetchToStore() (e.g. in `nix
registry pin`), the narHash attribute will never be added. This could
lead to a mismatch.
  • Loading branch information
edolstra committed Oct 16, 2024
1 parent fc09815 commit ed1f9dd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/libfetchers/fetchers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ std::pair<StorePath, Input> Input::fetchToStore(ref<Store> store) const
auto narHash = store->queryPathInfo(storePath)->narHash;
final.attrs.insert_or_assign("narHash", narHash.to_string(HashFormat::SRI, true));

// FIXME: we would like to mark inputs as final in
// getAccessorUnchecked(), but then we can't add
// narHash. Or maybe narHash should be excluded from the
// concept of "final" inputs?
final.attrs.insert_or_assign("final", Explicit<bool>(true));

assert(final.isFinal());

scheme->checkLocks(*this, final);

return {storePath, final};
Expand Down Expand Up @@ -228,8 +236,6 @@ void InputScheme::checkLocks(const Input & specified, const Input & final) const
final.to_string(), *prevRevCount);
}

assert(final.isFinal());

if (specified.isFinal() && specified.attrs != final.attrs)
throw Error("fetching final input '%s' resulted in different input '%s'",
attrsToJSON(specified.attrs), attrsToJSON(final.attrs));
Expand Down Expand Up @@ -291,8 +297,6 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(ref<Store> sto
assert(!accessor->fingerprint);
accessor->fingerprint = scheme->getFingerprint(store, final);

final.attrs.insert_or_assign("final", Explicit<bool>(true));

return {accessor, std::move(final)};
}

Expand Down

0 comments on commit ed1f9dd

Please sign in to comment.