MCPcopy Create free account
hub / github.com/GothenburgBitFactory/taskwarrior / execute

Method execute

src/commands/CmdSync.cpp:59–180  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

57
58////////////////////////////////////////////////////////////////////////////////
59int CmdSync::execute(std::string& output) {
60 int status = 0;
61
62 Context& context = Context::getContext();
63 auto& replica = context.tdb2.replica();
64 std::stringstream out;
65 bool avoid_snapshots = false;
66 bool verbose = Context::getContext().verbose("sync");
67
68 std::string origin = Context::getContext().config.get("sync.server.origin");
69 std::string url = Context::getContext().config.get("sync.server.url");
70 std::string server_dir = Context::getContext().config.get("sync.local.server_dir");
71 std::string client_id = Context::getContext().config.get("sync.server.client_id");
72 std::string aws_bucket = Context::getContext().config.get("sync.aws.bucket");
73 std::string gcp_bucket = Context::getContext().config.get("sync.gcp.bucket");
74 std::string encryption_secret = Context::getContext().config.get("sync.encryption_secret");
75
76 // sync.server.origin is a deprecated synonym for sync.server.url
77 std::string server_url = url == "" ? origin : url;
78 if (origin != "") {
79 out << "sync.server.origin is deprecated. Use sync.server.url instead.\n";
80 }
81
82 // redact credentials from `server_url`, if present
83 std::regex remove_creds_regex("^(https?://.+):(.+)@(.+)");
84 std::string safe_server_url = std::regex_replace(server_url, remove_creds_regex, "$1:****@$3");
85
86 auto num_local_operations = replica->num_local_operations();
87
88 if (server_dir != "") {
89 if (verbose) {
90 out << format("Syncing with {1}", server_dir) << '\n';
91 }
92 replica->sync_to_local(server_dir, avoid_snapshots);
93 } else if (aws_bucket != "") {
94 std::string aws_region = Context::getContext().config.get("sync.aws.region");
95 std::string aws_profile = Context::getContext().config.get("sync.aws.profile");
96 std::string aws_access_key_id = Context::getContext().config.get("sync.aws.access_key_id");
97 std::string aws_secret_access_key =
98 Context::getContext().config.get("sync.aws.secret_access_key");
99 std::string aws_default_credentials =
100 Context::getContext().config.get("sync.aws.default_credentials");
101 if (aws_region == "") {
102 throw std::string("sync.aws.region is required");
103 }
104 if (encryption_secret == "") {
105 throw std::string("sync.encryption_secret is required");
106 }
107
108 bool using_profile = false;
109 bool using_creds = false;
110 bool using_default = false;
111 if (aws_profile != "") {
112 using_profile = true;
113 }
114 if (aws_access_key_id != "" || aws_secret_access_key != "") {
115 using_creds = true;
116 }

Callers

nothing calls this directly

Calls 11

uuid_from_stringFunction · 0.85
verboseMethod · 0.80
num_local_operationsMethod · 0.80
sync_to_localMethod · 0.80
sync_to_gcpMethod · 0.80
sync_to_remoteMethod · 0.80
getMethod · 0.45
expire_tasksMethod · 0.45

Tested by

no test coverage detected