From 430bcda3eab685e272b4fd71c5ee073c1f39caed Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Sun, 30 Nov 2025 18:49:11 +0300 Subject: [PATCH] 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. --- src/libstore/filetransfer.cc | 10 ++++---- .../include/nix/store/filetransfer.hh | 24 +++++++++++++++---- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index 57caec384..f242b1851 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -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; diff --git a/src/libstore/include/nix/store/filetransfer.hh b/src/libstore/include/nix/store/filetransfer.hh index 76d036a78..57b781c33 100644 --- a/src/libstore/include/nix/store/filetransfer.hh +++ b/src/libstore/include/nix/store/filetransfer.hh @@ -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(); }