mirror of
https://github.com/NixOS/nix.git
synced 2025-11-22 02:09:36 +01:00
libstore: Slightly deindent writeCallback by wrapping it in try/catch
The indentation level of the code is already high enough. We can just wrap the whole function in a try/catch and mark it noexcept. Partially cherry-picked from https://gerrit.lix.systems/c/lix/+/2133 Co-authored-by: eldritch horrors <pennae@lix.systems>
This commit is contained in:
parent
09d6847490
commit
6d65f8eea2
1 changed files with 19 additions and 21 deletions
|
|
@ -170,30 +170,28 @@ struct curlFileTransfer : public FileTransfer
|
||||||
|
|
||||||
std::exception_ptr writeException;
|
std::exception_ptr writeException;
|
||||||
|
|
||||||
size_t writeCallback(void * contents, size_t size, size_t nmemb)
|
size_t writeCallback(void * contents, size_t size, size_t nmemb) noexcept
|
||||||
{
|
try {
|
||||||
try {
|
size_t realSize = size * nmemb;
|
||||||
size_t realSize = size * nmemb;
|
result.bodySize += realSize;
|
||||||
result.bodySize += realSize;
|
|
||||||
|
|
||||||
if (!decompressionSink) {
|
if (!decompressionSink) {
|
||||||
decompressionSink = makeDecompressionSink(encoding, finalSink);
|
decompressionSink = makeDecompressionSink(encoding, finalSink);
|
||||||
if (!successfulStatuses.count(getHTTPStatus())) {
|
if (!successfulStatuses.count(getHTTPStatus())) {
|
||||||
// In this case we want to construct a TeeSink, to keep
|
// In this case we want to construct a TeeSink, to keep
|
||||||
// the response around (which we figure won't be big
|
// the response around (which we figure won't be big
|
||||||
// like an actual download should be) to improve error
|
// like an actual download should be) to improve error
|
||||||
// messages.
|
// messages.
|
||||||
errorSink = StringSink{};
|
errorSink = StringSink{};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(*decompressionSink)({(char *) contents, realSize});
|
|
||||||
|
|
||||||
return realSize;
|
|
||||||
} catch (...) {
|
|
||||||
writeException = std::current_exception();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(*decompressionSink)({(char *) contents, realSize});
|
||||||
|
|
||||||
|
return realSize;
|
||||||
|
} catch (...) {
|
||||||
|
writeException = std::current_exception();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t writeCallbackWrapper(void * contents, size_t size, size_t nmemb, void * userp)
|
static size_t writeCallbackWrapper(void * contents, size_t size, size_t nmemb, void * userp)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue