1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-04 16:10:59 +01:00

Merge pull request #14675 from NixOS/cleanup-verb-filetransfer

libstore: Split FileTransferRequest::verb into verb + noun
This commit is contained in:
John Ericson 2025-11-30 16:59:56 +00:00 committed by GitHub
commit 5b175ace18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 10 deletions

View file

@ -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;

View file

@ -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();
}