Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 31 additions & 27 deletions src/libexpr/primops/fetchTree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -451,35 +451,39 @@ static void fetch(
}
}

// Download the file/tarball if substitution failed or no hash was provided
auto storePath = unpack ? fetchToStore(
state.fetchSettings,
*state.store,
fetchers::downloadTarball(*state.store, state.fetchSettings, *url),
FetchMode::Copy,
name)
: fetchers::downloadFile(*state.store, state.fetchSettings, *url, name).storePath;

if (expectedHash) {
auto hash = unpack ? state.store->queryPathInfo(storePath)->narHash
: hashPath(
{state.store->requireStoreObjectAccessor(storePath)},
FileSerialisationMethod::Flat,
HashAlgorithm::SHA256)
.hash;
if (hash != *expectedHash) {
state
.error<EvalError>(
"hash mismatch in file downloaded from '%s':\n specified: %s\n got: %s",
*url,
expectedHash->to_string(HashFormat::Nix32, true),
hash.to_string(HashFormat::Nix32, true))
.withExitStatus(102)
.debugThrow();
if (unpack) {
auto attrs = fetchers::Attrs{
{"type", "tarball"},
{"url", *url},
{"name", name},
};
if (expectedHash)
attrs.emplace("narHash", expectedHash->to_string(HashFormat::SRI, true));
auto input = fetchers::Input::fromAttrs(state.fetchSettings, std::move(attrs));
Comment thread
coderabbitai[bot] marked this conversation as resolved.
auto cachedInput =
state.inputCache->getAccessor(state.fetchSettings, *state.store, input, fetchers::UseRegistries::No);
auto storePath = state.mountInput(cachedInput.lockedInput, input, cachedInput.accessor, false);
state.mkStorePathString(storePath, v);
} else {
auto storePath = fetchers::downloadFile(*state.store, state.fetchSettings, *url, name).storePath;
if (expectedHash) {
auto hash = hashPath(
{state.store->requireStoreObjectAccessor(storePath)},
FileSerialisationMethod::Flat,
HashAlgorithm::SHA256)
.hash;
if (hash != *expectedHash)
state
.error<EvalError>(
"hash mismatch in file downloaded from '%s':\n specified: %s\n got: %s",
*url,
expectedHash->to_string(HashFormat::Nix32, true),
hash.to_string(HashFormat::Nix32, true))
.withExitStatus(102)
.debugThrow();
}
state.allowAndSetStorePathString(storePath, v);
}

state.allowAndSetStorePathString(storePath, v);
}

static void prim_fetchurl(EvalState & state, const PosIdx pos, Value ** args, Value & v)
Expand Down
Loading