mirror of
https://github.com/NixOS/nix.git
synced 2025-12-04 08:00:59 +01:00
libstore: Split FileTransferRequest::verb into verb + noun
With the addition of "delete" method we can no longer rely on just concatenating "ing" to get the continuous form of the verb. Also some use-cases actually need a noun instead.
This commit is contained in:
parent
048a58d331
commit
430bcda3ea
2 changed files with 24 additions and 10 deletions
|
|
@ -101,7 +101,7 @@ struct curlFileTransfer : public FileTransfer
|
|||
, act(*logger,
|
||||
lvlTalkative,
|
||||
actFileTransfer,
|
||||
fmt("%sing '%s'", request.verb(), request.uri),
|
||||
fmt("%s '%s'", request.verb(/*continuous=*/true), request.uri),
|
||||
{request.uri.to_string()},
|
||||
request.parentAct)
|
||||
, callback(std::move(callback))
|
||||
|
|
@ -166,7 +166,7 @@ struct curlFileTransfer : public FileTransfer
|
|||
std::rethrow_exception(ex);
|
||||
} catch (nix::Error & e) {
|
||||
/* Add more context to the error message. */
|
||||
e.addTrace({}, "during %s of '%s'", Uncolored(request.verb()), request.uri.to_string());
|
||||
e.addTrace({}, "during %s of '%s'", Uncolored(request.noun()), request.uri.to_string());
|
||||
} catch (...) {
|
||||
/* Can't add more context to the error. */
|
||||
}
|
||||
|
|
@ -510,7 +510,7 @@ struct curlFileTransfer : public FileTransfer
|
|||
|
||||
debug(
|
||||
"finished %s of '%s'; curl status = %d, HTTP status = %d, body = %d bytes, duration = %.2f s",
|
||||
request.verb(),
|
||||
request.noun(),
|
||||
request.uri,
|
||||
code,
|
||||
httpStatus,
|
||||
|
|
@ -610,7 +610,7 @@ struct curlFileTransfer : public FileTransfer
|
|||
Interrupted,
|
||||
std::move(response),
|
||||
"%s of '%s' was interrupted",
|
||||
request.verb(),
|
||||
request.noun(),
|
||||
request.uri)
|
||||
: httpStatus != 0
|
||||
? FileTransferError(
|
||||
|
|
@ -845,7 +845,7 @@ struct curlFileTransfer : public FileTransfer
|
|||
}
|
||||
|
||||
for (auto & item : incoming) {
|
||||
debug("starting %s of %s", item->request.verb(), item->request.uri);
|
||||
debug("starting %s of %s", item->request.noun(), item->request.uri);
|
||||
item->init();
|
||||
curl_multi_add_handle(curlm, item->req);
|
||||
item->active = true;
|
||||
|
|
|
|||
|
|
@ -169,11 +169,25 @@ struct FileTransferRequest
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the verb root for logging purposes.
|
||||
* The returned string is intended to be concatenated with "ing" to form the gerund,
|
||||
* e.g., "download" + "ing" -> "downloading", "upload" + "ing" -> "uploading".
|
||||
* Returns the method description for logging purposes.
|
||||
*/
|
||||
std::string verb() const
|
||||
std::string verb(bool continuous = false) const
|
||||
{
|
||||
switch (method) {
|
||||
case HttpMethod::Head:
|
||||
case HttpMethod::Get:
|
||||
return continuous ? "downloading" : "download";
|
||||
case HttpMethod::Put:
|
||||
case HttpMethod::Post:
|
||||
assert(data);
|
||||
return continuous ? "uploading" : "upload";
|
||||
case HttpMethod::Delete:
|
||||
return continuous ? "deleting" : "delete";
|
||||
}
|
||||
unreachable();
|
||||
}
|
||||
|
||||
std::string noun() const
|
||||
{
|
||||
switch (method) {
|
||||
case HttpMethod::Head:
|
||||
|
|
@ -184,7 +198,7 @@ struct FileTransferRequest
|
|||
assert(data);
|
||||
return "upload";
|
||||
case HttpMethod::Delete:
|
||||
return "delet";
|
||||
return "deletion";
|
||||
}
|
||||
unreachable();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue