1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-25 19:51:00 +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] =
mode == FetchMode::DryRun
? ({
auto [storePath, hash] = store.computeStorePath( auto [storePath, hash] = store.computeStorePath(
name, path, method, HashAlgorithm::SHA256, {}, filter2); name, path, method, HashAlgorithm::SHA256, {}, filter2);
debug("hashed '%s' to '%s'", path, store.printStorePath(storePath)); debug("hashed '%s' to '%s' (hash '%s')", path, store.printStorePath(storePath), hash.to_string(HashFormat::SRI, true));
if (cacheKey) std::make_pair(storePath, hash);
fetchers::getCache()->upsert(*cacheKey, {{"hash", hash.to_string(HashFormat::SRI, true)}}); })
return {storePath, hash}; : ({
} else { // FIXME: ideally addToStore() would return the hash
// right away (like computeStorePath()).
auto storePath = store.addToStore( auto storePath = store.addToStore(
name, path, method, HashAlgorithm::SHA256, {}, filter2, repair); name, path, method, HashAlgorithm::SHA256, {}, filter2, repair);
debug("copied '%s' to '%s'", path, store.printStorePath(storePath)); auto info = store.queryPathInfo(storePath);
// FIXME: this is the wrong hash when method != assert(info->references.empty());
// ContentAddressMethod::Raw::NixArchive. Doesn't matter at auto hash =
// the moment since the only place where that's the case method == ContentAddressMethod::Raw::NixArchive
// doesn't use the hash. ? info->narHash
auto hash = store.queryPathInfo(storePath)->narHash; : ({
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) if (cacheKey)
fetchers::getCache()->upsert(*cacheKey, {{"hash", hash.to_string(HashFormat::SRI, true)}}); fetchers::getCache()->upsert(*cacheKey, {{"hash", hash.to_string(HashFormat::SRI, true)}});
return {storePath, hash}; return {storePath, hash};
}
} }
} }