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:
@@ -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);
|
||||
|
||||
|
||||
@@ -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)};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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 };
|
||||
};
|
||||
|
||||
@@ -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
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user