libstore: extract eager transfers into new method
we'll need this shared code for kjified transfers that don't use
sources. it's a while out, but we can clean this up now already.
Change-Id: Ife8c160e6ab379761362d6c54aba05093deee99e
This commit is contained in:
parent
12156d3beb
commit
fb85228755
|
@ -720,10 +720,10 @@ struct curlFileTransfer : public FileTransfer
|
||||||
enqueueFileTransfer(uri, headers, std::move(data), false);
|
enqueueFileTransfer(uri, headers, std::move(data), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<FileTransferResult, box_ptr<Source>> enqueueFileTransfer(
|
std::optional<std::pair<FileTransferResult, box_ptr<Source>>> tryEagerTransfers(
|
||||||
const std::string & uri,
|
const std::string & uri,
|
||||||
const Headers & headers,
|
const Headers & headers,
|
||||||
std::optional<std::string> data,
|
const std::optional<std::string> & data,
|
||||||
bool noBody
|
bool noBody
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -767,14 +767,14 @@ struct curlFileTransfer : public FileTransfer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (S_ISDIR(st.st_mode)) {
|
if (S_ISDIR(st.st_mode)) {
|
||||||
return {std::move(metadata), make_box_ptr<StringSource>("")};
|
return {{std::move(metadata), make_box_ptr<StringSource>("")}};
|
||||||
}
|
}
|
||||||
struct OwningFdSource : FdSource
|
struct OwningFdSource : FdSource
|
||||||
{
|
{
|
||||||
AutoCloseFD fd;
|
AutoCloseFD fd;
|
||||||
OwningFdSource(AutoCloseFD fd) : FdSource(fd.get()), fd(std::move(fd)) {}
|
OwningFdSource(AutoCloseFD fd) : FdSource(fd.get()), fd(std::move(fd)) {}
|
||||||
};
|
};
|
||||||
return {std::move(metadata), make_box_ptr<OwningFdSource>(std::move(fd))};
|
return {{std::move(metadata), make_box_ptr<OwningFdSource>(std::move(fd))}};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -796,7 +796,7 @@ struct curlFileTransfer : public FileTransfer
|
||||||
FileTransferResult res;
|
FileTransferResult res;
|
||||||
if (!s3Res.data)
|
if (!s3Res.data)
|
||||||
throw FileTransferError(NotFound, "S3 object '%s' does not exist", uri);
|
throw FileTransferError(NotFound, "S3 object '%s' does not exist", uri);
|
||||||
return {res, make_box_ptr<StringSource>(std::move(*s3Res.data))};
|
return {{res, make_box_ptr<StringSource>(std::move(*s3Res.data))}};
|
||||||
#else
|
#else
|
||||||
throw nix::Error(
|
throw nix::Error(
|
||||||
"cannot download '%s' because Lix is not built with S3 support", uri
|
"cannot download '%s' because Lix is not built with S3 support", uri
|
||||||
|
@ -804,6 +804,20 @@ struct curlFileTransfer : public FileTransfer
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<FileTransferResult, box_ptr<Source>> enqueueFileTransfer(
|
||||||
|
const std::string & uri,
|
||||||
|
const Headers & headers,
|
||||||
|
std::optional<std::string> data,
|
||||||
|
bool noBody
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (auto eager = tryEagerTransfers(uri, headers, data, noBody)) {
|
||||||
|
return std::move(*eager);
|
||||||
|
}
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
bool done = false, failed = false;
|
bool done = false, failed = false;
|
||||||
std::exception_ptr exc;
|
std::exception_ptr exc;
|
||||||
|
|
Loading…
Reference in a new issue