1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-26 04:00:59 +01:00

fetchToStore(): Address a FIXME

This commit is contained in:
Eelco Dolstra 2025-06-16 16:05:08 +02:00 committed by Graham Christensen
parent e3fa4faff9
commit b2905dc08e

View file

@ -64,26 +64,37 @@ std::pair<StorePath, Hash> fetchToStore2(
auto filter2 = filter ? *filter : defaultPathFilter; auto filter2 = filter ? *filter : defaultPathFilter;
if (mode == FetchMode::DryRun) { auto [storePath, hash] =
auto [storePath, hash] = store.computeStorePath( mode == FetchMode::DryRun
name, path, method, HashAlgorithm::SHA256, {}, filter2); ? ({
debug("hashed '%s' to '%s'", path, store.printStorePath(storePath)); auto [storePath, hash] = store.computeStorePath(
if (cacheKey) name, path, method, HashAlgorithm::SHA256, {}, filter2);
fetchers::getCache()->upsert(*cacheKey, {{"hash", hash.to_string(HashFormat::SRI, true)}}); debug("hashed '%s' to '%s' (hash '%s')", path, store.printStorePath(storePath), hash.to_string(HashFormat::SRI, true));
return {storePath, hash}; std::make_pair(storePath, hash);
} else { })
auto storePath = store.addToStore( : ({
name, path, method, HashAlgorithm::SHA256, {}, filter2, repair); // FIXME: ideally addToStore() would return the hash
debug("copied '%s' to '%s'", path, store.printStorePath(storePath)); // right away (like computeStorePath()).
// FIXME: this is the wrong hash when method != auto storePath = store.addToStore(
// ContentAddressMethod::Raw::NixArchive. Doesn't matter at name, path, method, HashAlgorithm::SHA256, {}, filter2, repair);
// the moment since the only place where that's the case auto info = store.queryPathInfo(storePath);
// doesn't use the hash. assert(info->references.empty());
auto hash = store.queryPathInfo(storePath)->narHash; auto hash =
if (cacheKey) method == ContentAddressMethod::Raw::NixArchive
fetchers::getCache()->upsert(*cacheKey, {{"hash", hash.to_string(HashFormat::SRI, true)}}); ? info->narHash
return {storePath, hash}; : ({
} if (!info->ca || info->ca->method != method)
throw Error("path '%s' lacks a CA field", store.printStorePath(storePath));
info->ca->hash;
});
debug("copied '%s' to '%s' (hash '%s')", path, store.printStorePath(storePath), hash.to_string(HashFormat::SRI, true));
std::make_pair(storePath, hash);
});
if (cacheKey)
fetchers::getCache()->upsert(*cacheKey, {{"hash", hash.to_string(HashFormat::SRI, true)}});
return {storePath, hash};
} }
} }