mirror of
https://github.com/NixOS/nix.git
synced 2025-11-24 03:09:35 +01:00
Merge pull request #14630 from NixOS/prefetch-fixes
nix/prefetch: Be honest about when path name is derived from URL
This commit is contained in:
commit
487c6b6c46
1 changed files with 16 additions and 11 deletions
|
|
@ -59,7 +59,7 @@ std::string resolveMirrorUrl(EvalState & state, const std::string & url)
|
|||
std::tuple<StorePath, Hash> prefetchFile(
|
||||
ref<Store> store,
|
||||
const VerbatimURL & url,
|
||||
std::optional<std::string> name,
|
||||
std::optional<std::string> maybeName,
|
||||
HashAlgorithm hashAlgo,
|
||||
std::optional<Hash> expectedHash,
|
||||
bool unpack,
|
||||
|
|
@ -68,16 +68,21 @@ std::tuple<StorePath, Hash> prefetchFile(
|
|||
ContentAddressMethod method =
|
||||
unpack || executable ? ContentAddressMethod::Raw::NixArchive : ContentAddressMethod::Raw::Flat;
|
||||
|
||||
std::string name = maybeName
|
||||
.or_else([&]() {
|
||||
/* Figure out a name in the Nix store. */
|
||||
if (!name) {
|
||||
name = url.lastPathSegment();
|
||||
if (!name || name->empty())
|
||||
auto derivedFromUrl = url.lastPathSegment();
|
||||
if (!derivedFromUrl || derivedFromUrl->empty())
|
||||
throw Error("cannot figure out file name for '%s'", url.to_string());
|
||||
}
|
||||
return derivedFromUrl;
|
||||
})
|
||||
.value();
|
||||
|
||||
try {
|
||||
checkName(*name);
|
||||
checkName(name);
|
||||
} catch (BadStorePathName & e) {
|
||||
e.addTrace({}, "file name '%s' was extracted from URL '%s'", *name, url.to_string());
|
||||
if (!maybeName)
|
||||
e.addTrace({}, "file name '%s' was extracted from URL '%s'", name, url.to_string());
|
||||
throw;
|
||||
}
|
||||
|
||||
|
|
@ -89,7 +94,7 @@ std::tuple<StorePath, Hash> prefetchFile(
|
|||
if (expectedHash) {
|
||||
hashAlgo = expectedHash->algo;
|
||||
storePath =
|
||||
store->makeFixedOutputPathFromCA(*name, ContentAddressWithReferences::fromParts(method, *expectedHash, {}));
|
||||
store->makeFixedOutputPathFromCA(name, ContentAddressWithReferences::fromParts(method, *expectedHash, {}));
|
||||
if (store->isValidPath(*storePath))
|
||||
hash = expectedHash;
|
||||
else
|
||||
|
|
@ -138,7 +143,7 @@ std::tuple<StorePath, Hash> prefetchFile(
|
|||
|
||||
Activity act(*logger, lvlChatty, actUnknown, fmt("adding '%s' to the store", url.to_string()));
|
||||
|
||||
auto info = store->addToStoreSlow(*name, makeFSSourceAccessor(tmpFile), method, hashAlgo, {}, expectedHash);
|
||||
auto info = store->addToStoreSlow(name, makeFSSourceAccessor(tmpFile), method, hashAlgo, {}, expectedHash);
|
||||
storePath = info.path;
|
||||
assert(info.ca);
|
||||
hash = info.ca->hash;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue