libstore: return transfer metadata from download

as promised earlier. nothing uses it yet, but just you wait.

Change-Id: I77d185578d96c2134b756d20f2fcf1c02de0da6f
This commit is contained in:
eldritch horrors
2024-10-28 18:52:49 +00:00
parent 14eff10fe4
commit c68f0cdf00
6 changed files with 14 additions and 11 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ void builtinFetchurl(const BasicDerivation & drv, const std::string & netrcData,
auto fetch = [&](const std::string & url) {
auto raw = fileTransfer->download(url);
auto raw = fileTransfer->download(url).second;
auto decompressor = makeDecompressionSource(
unpack && mainUrl.ends_with(".xz") ? "xz" : "none", *raw);
+5 -3
View File
@@ -821,7 +821,8 @@ struct curlFileTransfer : public FileTransfer
}
}
box_ptr<Source> download(const std::string & uri, const Headers & headers) override
std::pair<FileTransferResult, box_ptr<Source>>
download(const std::string & uri, const Headers & headers) override
{
struct State {
bool done = false, failed = false;
@@ -832,7 +833,7 @@ struct curlFileTransfer : public FileTransfer
auto _state = std::make_shared<Sync<State>>();
auto transfer = enqueueFileTransfer(
auto [metadataFuture, _done] = enqueueFileTransfer(
uri,
headers,
[_state](std::exception_ptr ex) {
@@ -939,10 +940,11 @@ struct curlFileTransfer : public FileTransfer
}
};
auto metadata = metadataFuture.get();
auto source = make_box_ptr<DownloadSource>(_state);
auto lock(_state->lock());
source->awaitData(lock);
return source;
return {std::move(metadata), std::move(source)};
}
};
+2 -1
View File
@@ -101,7 +101,8 @@ struct FileTransfer
* thrown by the returned source. The source will only throw errors detected
* during the transfer itself (decompression errors, connection drops, etc).
*/
virtual box_ptr<Source> download(const std::string & uri, const Headers & headers = {}) = 0;
virtual std::pair<FileTransferResult, box_ptr<Source>>
download(const std::string & uri, const Headers & headers = {}) = 0;
enum Error { NotFound, Forbidden, Misc, Transient, Interrupted };
};
+1 -1
View File
@@ -147,7 +147,7 @@ protected:
{
checkEnabled();
try {
return getFileTransfer()->download(makeURI(path));
return getFileTransfer()->download(makeURI(path)).second;
} catch (FileTransferError & e) {
if (e.error == FileTransfer::NotFound || e.error == FileTransfer::Forbidden)
throw NoSuchBinaryCacheFile("file '%s' does not exist in binary cache '%s'", path, getUri());
+1 -1
View File
@@ -98,7 +98,7 @@ std::tuple<StorePath, Hash> prefetchFile(
FdSink sink(fd.get());
getFileTransfer()->download(url)->drainInto(sink);
getFileTransfer()->download(url).second->drainInto(sink);
}
/* Optionally unpack the file. */