Skip to content

Commit

Permalink
Rename Run/RunCallback to Finalize/RunCallback
Browse files Browse the repository at this point in the history
This makes a bit more sense. Finalize finishes the handler
lifecycle, RunCallback runs the callback.
  • Loading branch information
falconindy committed Sep 9, 2024
1 parent eea1701 commit da91b17
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/aur/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ class ResponseHandler {
return 0;
}

int RunCallback(absl::Status status) {
int r = Run(std::move(status));
int Finalize(absl::Status status) {
int r = RunCallback(std::move(status));
delete this;
return r;
}
Expand All @@ -175,7 +175,7 @@ class ResponseHandler {
std::array<char, CURL_ERROR_SIZE> error_buffer = {};

private:
virtual int Run(absl::Status status) = 0;
virtual int RunCallback(absl::Status status) = 0;

ClientImpl* client_;
};
Expand All @@ -193,7 +193,7 @@ class TypedResponseHandler : public ResponseHandler {
return ResponseT::Parse(std::move(body));
}

int Run(absl::Status status) override {
int RunCallback(absl::Status status) override {
if (status.ok()) {
return std::move(callback_)(MakeResponse());
} else {
Expand All @@ -210,15 +210,15 @@ class RpcResponseHandler : public TypedResponseHandler<RpcResponse> {
using TypedResponseHandler<RpcResponse>::TypedResponseHandler;

protected:
int Run(absl::Status status) override {
int RunCallback(absl::Status status) override {
if (!status.ok()) {
// The AUR might supply HTML on non-200 replies. We must avoid parsing
// this as JSON, so drop the response body and trust the callback to do
// the right thing with the error.
body.clear();
}

return TypedResponseHandler<RpcResponse>::Run(std::move(status));
return TypedResponseHandler<RpcResponse>::RunCallback(std::move(status));
}
};

Expand Down Expand Up @@ -439,7 +439,7 @@ int ClientImpl::FinishRequest(CURL* curl, CURLcode result,
result == CURLE_OK ? StatusFromCurlHandle(curl)
: absl::UnknownError(handler->error_buffer.data());

r = handler->RunCallback(std::move(status));
r = handler->Finalize(std::move(status));
} else {
delete handler;
}
Expand Down Expand Up @@ -541,7 +541,7 @@ int ClientImpl::OnCloneExit(sd_event_source* source, const siginfo_t* si,
absl::StrCat("git exited with unexpected exit status ", si->si_status));
}

return handler->RunCallback(std::move(status));
return handler->Finalize(std::move(status));
}

void ClientImpl::QueueCloneRequest(const CloneRequest& request,
Expand All @@ -553,7 +553,7 @@ void ClientImpl::QueueCloneRequest(const CloneRequest& request,

int pid = fork();
if (pid < 0) {
handler->RunCallback(absl::InternalError(
handler->Finalize(absl::InternalError(
absl::StrCat("failed to fork new process for git: ", strerror(errno))));
return;
}
Expand Down

0 comments on commit da91b17

Please sign in to comment.