Fix #3571: Added detailed feedback for successful task synchronization (#3758)

* Fix #3571: Added detailed feedback for successful task synchronization

* Refactor sync logic and add verbose output for synchronization operations

* Give a count of local operations sent

---------

Co-authored-by: Antoni Borowski <antoniborowski11@gmail.com>
Co-authored-by: Dustin J. Mitchell <dustin@v.igoro.us>
This commit is contained in:
Antoni Borowski 2025-05-08 00:29:19 +02:00 committed by GitHub
parent 97bcc76ac1
commit 0e59a62ead
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -83,6 +83,8 @@ int CmdSync::execute(std::string& output) {
std::regex remove_creds_regex("^(https?://.+):(.+)@(.+)"); std::regex remove_creds_regex("^(https?://.+):(.+)@(.+)");
std::string safe_server_url = std::regex_replace(server_url, remove_creds_regex, "$1:****@$3"); std::string safe_server_url = std::regex_replace(server_url, remove_creds_regex, "$1:****@$3");
auto num_local_operations = replica->num_local_operations();
if (server_dir != "") { if (server_dir != "") {
if (verbose) { if (verbose) {
out << format("Syncing with {1}", server_dir) << '\n'; out << format("Syncing with {1}", server_dir) << '\n';
@ -135,6 +137,7 @@ int CmdSync::execute(std::string& output) {
replica->sync_to_aws_with_default_creds(aws_region, aws_bucket, encryption_secret, replica->sync_to_aws_with_default_creds(aws_region, aws_bucket, encryption_secret,
avoid_snapshots); avoid_snapshots);
} }
} else if (gcp_bucket != "") { } else if (gcp_bucket != "") {
std::string gcp_credential_path = Context::getContext().config.get("sync.gcp.credential_path"); std::string gcp_credential_path = Context::getContext().config.get("sync.gcp.credential_path");
if (encryption_secret == "") { if (encryption_secret == "") {
@ -144,6 +147,7 @@ int CmdSync::execute(std::string& output) {
out << format("Syncing with GCP bucket {1}", gcp_bucket) << '\n'; out << format("Syncing with GCP bucket {1}", gcp_bucket) << '\n';
} }
replica->sync_to_gcp(gcp_bucket, gcp_credential_path, encryption_secret, avoid_snapshots); replica->sync_to_gcp(gcp_bucket, gcp_credential_path, encryption_secret, avoid_snapshots);
} else if (server_url != "") { } else if (server_url != "") {
if (client_id == "" || encryption_secret == "") { if (client_id == "" || encryption_secret == "") {
throw std::string("sync.server.client_id and sync.encryption_secret are required"); throw std::string("sync.server.client_id and sync.encryption_secret are required");
@ -153,6 +157,7 @@ int CmdSync::execute(std::string& output) {
} }
replica->sync_to_remote(server_url, tc::uuid_from_string(client_id), encryption_secret, replica->sync_to_remote(server_url, tc::uuid_from_string(client_id), encryption_secret,
avoid_snapshots); avoid_snapshots);
} else { } else {
throw std::string("No sync.* settings are configured. See task-sync(5)."); throw std::string("No sync.* settings are configured. See task-sync(5).");
} }
@ -161,6 +166,15 @@ int CmdSync::execute(std::string& output) {
context.tdb2.expire_tasks(); context.tdb2.expire_tasks();
} }
if (verbose) {
out << "Success!\n";
// Taskchampion does not provide a measure of the number of operations received from
// the server, but we can give some indication of the number sent.
if (num_local_operations) {
out << format("Sent {1} local operations to the server", num_local_operations) << '\n';
}
}
output = out.str(); output = out.str();
return status; return status;
} }