mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-29 17:16:15 +02:00
Merge pull request #4595 from dramforever/fetcher-http-redirect
libfetchers/tarball: Lock on effectiveUrl
This commit is contained in:
commit
1b2f5786d1
3 changed files with 24 additions and 9 deletions
|
@ -145,7 +145,13 @@ DownloadFileResult downloadFile(
|
|||
bool immutable,
|
||||
const Headers & headers = {});
|
||||
|
||||
std::pair<Tree, time_t> downloadTarball(
|
||||
struct DownloadTarballMeta
|
||||
{
|
||||
time_t lastModified;
|
||||
std::string effectiveUrl;
|
||||
};
|
||||
|
||||
std::pair<Tree, DownloadTarballMeta> downloadTarball(
|
||||
ref<Store> store,
|
||||
const std::string & url,
|
||||
const std::string & name,
|
||||
|
|
|
@ -207,16 +207,16 @@ struct GitArchiveInputScheme : InputScheme
|
|||
|
||||
auto url = getDownloadUrl(input);
|
||||
|
||||
auto [tree, lastModified] = downloadTarball(store, url.url, "source", true, url.headers);
|
||||
auto [tree, meta] = downloadTarball(store, url.url, "source", true, url.headers);
|
||||
|
||||
input.attrs.insert_or_assign("lastModified", uint64_t(lastModified));
|
||||
input.attrs.insert_or_assign("lastModified", uint64_t(meta.lastModified));
|
||||
|
||||
getCache()->add(
|
||||
store,
|
||||
immutableAttrs,
|
||||
{
|
||||
{"rev", rev->gitRev()},
|
||||
{"lastModified", uint64_t(lastModified)}
|
||||
{"lastModified", uint64_t(meta.lastModified)}
|
||||
},
|
||||
tree.storePath,
|
||||
true);
|
||||
|
|
|
@ -109,7 +109,7 @@ DownloadFileResult downloadFile(
|
|||
};
|
||||
}
|
||||
|
||||
std::pair<Tree, time_t> downloadTarball(
|
||||
std::pair<Tree, DownloadTarballMeta> downloadTarball(
|
||||
ref<Store> store,
|
||||
const std::string & url,
|
||||
const std::string & name,
|
||||
|
@ -127,7 +127,10 @@ std::pair<Tree, time_t> downloadTarball(
|
|||
if (cached && !cached->expired)
|
||||
return {
|
||||
Tree(store->toRealPath(cached->storePath), std::move(cached->storePath)),
|
||||
getIntAttr(cached->infoAttrs, "lastModified")
|
||||
{
|
||||
.lastModified = time_t(getIntAttr(cached->infoAttrs, "lastModified")),
|
||||
.effectiveUrl = maybeGetStrAttr(cached->infoAttrs, "effectiveUrl").value_or(url),
|
||||
},
|
||||
};
|
||||
|
||||
auto res = downloadFile(store, url, name, immutable, headers);
|
||||
|
@ -152,6 +155,7 @@ std::pair<Tree, time_t> downloadTarball(
|
|||
|
||||
Attrs infoAttrs({
|
||||
{"lastModified", uint64_t(lastModified)},
|
||||
{"effectiveUrl", res.effectiveUrl},
|
||||
{"etag", res.etag},
|
||||
});
|
||||
|
||||
|
@ -164,7 +168,10 @@ std::pair<Tree, time_t> downloadTarball(
|
|||
|
||||
return {
|
||||
Tree(store->toRealPath(*unpackedStorePath), std::move(*unpackedStorePath)),
|
||||
lastModified,
|
||||
{
|
||||
.lastModified = lastModified,
|
||||
.effectiveUrl = res.effectiveUrl,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -223,9 +230,11 @@ struct TarballInputScheme : InputScheme
|
|||
return true;
|
||||
}
|
||||
|
||||
std::pair<Tree, Input> fetch(ref<Store> store, const Input & input) override
|
||||
std::pair<Tree, Input> fetch(ref<Store> store, const Input & _input) override
|
||||
{
|
||||
auto tree = downloadTarball(store, getStrAttr(input.attrs, "url"), "source", false).first;
|
||||
Input input(_input);
|
||||
auto [tree, meta] = downloadTarball(store, getStrAttr(input.attrs, "url"), "source", false);
|
||||
input.attrs.insert_or_assign("url", meta.effectiveUrl);
|
||||
return {std::move(tree), input};
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue