mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-15 02:36:16 +02:00
Merge pull request #11285 from DeterminateSystems/downloadTarball-cacheable
fetchers::downloadTarball(): Return a cacheable accessor
This commit is contained in:
commit
92df2a7cb2
5 changed files with 35 additions and 8 deletions
|
@ -171,7 +171,9 @@ SourcePath lookupFileArg(EvalState & state, std::string_view s, const Path * bas
|
||||||
{
|
{
|
||||||
if (EvalSettings::isPseudoUrl(s)) {
|
if (EvalSettings::isPseudoUrl(s)) {
|
||||||
auto accessor = fetchers::downloadTarball(
|
auto accessor = fetchers::downloadTarball(
|
||||||
EvalSettings::resolvePseudoUrl(s)).accessor;
|
state.store,
|
||||||
|
state.fetchSettings,
|
||||||
|
EvalSettings::resolvePseudoUrl(s));
|
||||||
auto storePath = fetchToStore(*state.store, SourcePath(accessor), FetchMode::Copy);
|
auto storePath = fetchToStore(*state.store, SourcePath(accessor), FetchMode::Copy);
|
||||||
return state.rootPath(CanonPath(state.store->toRealPath(storePath)));
|
return state.rootPath(CanonPath(state.store->toRealPath(storePath)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3088,7 +3088,9 @@ std::optional<std::string> EvalState::resolveLookupPathPath(const LookupPath::Pa
|
||||||
if (EvalSettings::isPseudoUrl(value)) {
|
if (EvalSettings::isPseudoUrl(value)) {
|
||||||
try {
|
try {
|
||||||
auto accessor = fetchers::downloadTarball(
|
auto accessor = fetchers::downloadTarball(
|
||||||
EvalSettings::resolvePseudoUrl(value)).accessor;
|
store,
|
||||||
|
fetchSettings,
|
||||||
|
EvalSettings::resolvePseudoUrl(value));
|
||||||
auto storePath = fetchToStore(*store, SourcePath(accessor), FetchMode::Copy);
|
auto storePath = fetchToStore(*store, SourcePath(accessor), FetchMode::Copy);
|
||||||
return finish(store->toRealPath(storePath));
|
return finish(store->toRealPath(storePath));
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
|
|
|
@ -507,7 +507,11 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v
|
||||||
// https://github.com/NixOS/nix/issues/4313
|
// https://github.com/NixOS/nix/issues/4313
|
||||||
auto storePath =
|
auto storePath =
|
||||||
unpack
|
unpack
|
||||||
? fetchToStore(*state.store, fetchers::downloadTarball(*url).accessor, FetchMode::Copy, name)
|
? fetchToStore(
|
||||||
|
*state.store,
|
||||||
|
fetchers::downloadTarball(state.store, state.fetchSettings, *url),
|
||||||
|
FetchMode::Copy,
|
||||||
|
name)
|
||||||
: fetchers::downloadFile(state.store, *url, name).storePath;
|
: fetchers::downloadFile(state.store, *url, name).storePath;
|
||||||
|
|
||||||
if (expectedHash) {
|
if (expectedHash) {
|
||||||
|
|
|
@ -102,7 +102,7 @@ DownloadFileResult downloadFile(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadTarballResult downloadTarball(
|
static DownloadTarballResult downloadTarball_(
|
||||||
const std::string & url,
|
const std::string & url,
|
||||||
const Headers & headers)
|
const Headers & headers)
|
||||||
{
|
{
|
||||||
|
@ -202,6 +202,22 @@ DownloadTarballResult downloadTarball(
|
||||||
return attrsToResult(infoAttrs);
|
return attrsToResult(infoAttrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ref<SourceAccessor> downloadTarball(
|
||||||
|
ref<Store> store,
|
||||||
|
const Settings & settings,
|
||||||
|
const std::string & url)
|
||||||
|
{
|
||||||
|
/* Go through Input::getAccessor() to ensure that the resulting
|
||||||
|
accessor has a fingerprint. */
|
||||||
|
fetchers::Attrs attrs;
|
||||||
|
attrs.insert_or_assign("type", "tarball");
|
||||||
|
attrs.insert_or_assign("url", url);
|
||||||
|
|
||||||
|
auto input = Input::fromAttrs(settings, std::move(attrs));
|
||||||
|
|
||||||
|
return input.getAccessor(store).first;
|
||||||
|
}
|
||||||
|
|
||||||
// An input scheme corresponding to a curl-downloadable resource.
|
// An input scheme corresponding to a curl-downloadable resource.
|
||||||
struct CurlInputScheme : InputScheme
|
struct CurlInputScheme : InputScheme
|
||||||
{
|
{
|
||||||
|
@ -353,7 +369,7 @@ struct TarballInputScheme : CurlInputScheme
|
||||||
{
|
{
|
||||||
auto input(_input);
|
auto input(_input);
|
||||||
|
|
||||||
auto result = downloadTarball(getStrAttr(input.attrs, "url"), {});
|
auto result = downloadTarball_(getStrAttr(input.attrs, "url"), {});
|
||||||
|
|
||||||
result.accessor->setPathDisplay("«" + input.to_string() + "»");
|
result.accessor->setPathDisplay("«" + input.to_string() + "»");
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,8 @@ struct SourceAccessor;
|
||||||
|
|
||||||
namespace nix::fetchers {
|
namespace nix::fetchers {
|
||||||
|
|
||||||
|
struct Settings;
|
||||||
|
|
||||||
struct DownloadFileResult
|
struct DownloadFileResult
|
||||||
{
|
{
|
||||||
StorePath storePath;
|
StorePath storePath;
|
||||||
|
@ -40,8 +42,9 @@ struct DownloadTarballResult
|
||||||
* Download and import a tarball into the Git cache. The result is the
|
* Download and import a tarball into the Git cache. The result is the
|
||||||
* Git tree hash of the root directory.
|
* Git tree hash of the root directory.
|
||||||
*/
|
*/
|
||||||
DownloadTarballResult downloadTarball(
|
ref<SourceAccessor> downloadTarball(
|
||||||
const std::string & url,
|
ref<Store> store,
|
||||||
const Headers & headers = {});
|
const Settings & settings,
|
||||||
|
const std::string & url);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue