• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

GothenburgBitFactory / taskwarrior / 12837448009

17 Jan 2025 09:54PM UTC coverage: 84.938% (-0.1%) from 85.036%
12837448009

Pull #3758

github

web-flow
Merge b3c86a86f into 1c9dddcae
Pull Request #3758: Fix #3571: Added detailed feedback for successful task synchronization

1 of 4 new or added lines in 1 file covered. (25.0%)

22 existing lines in 3 files now uncovered.

19438 of 22885 relevant lines covered (84.94%)

23159.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

45.88
/src/commands/CmdSync.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2006 - 2021, Tomas Babej, Paul Beckingham, Federico Hernandez.
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
11
//
12
// The above copyright notice and this permission notice shall be included
13
// in all copies or substantial portions of the Software.
14
//
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
// SOFTWARE.
22
//
23
// https://www.opensource.org/licenses/mit-license.php
24
//
25
////////////////////////////////////////////////////////////////////////////////
26

27
#include <cmake.h>
28
// cmake.h include header must come first
29

30
#include <CmdSync.h>
31
#include <Color.h>
32
#include <Context.h>
33
#include <Filter.h>
34
#include <format.h>
35
#include <inttypes.h>
36
#include <shared.h>
37
#include <signal.h>
38
#include <taskchampion-cpp/lib.h>
39
#include <util.h>
40

41
#include <iostream>
42
#include <sstream>
43

44
////////////////////////////////////////////////////////////////////////////////
45
CmdSync::CmdSync() {
4,499✔
46
  _keyword = "synchronize";
4,499✔
47
  _usage = "task          synchronize [initialize]";
4,499✔
48
  _description = "Synchronizes data with the Taskserver";
4,499✔
49
  _read_only = false;
4,499✔
50
  _displays_id = false;
4,499✔
51
  _needs_gc = false;
4,499✔
52
  _uses_context = false;
4,499✔
53
  _accepts_filter = false;
4,499✔
54
  _accepts_modifications = false;
4,499✔
55
  _accepts_miscellaneous = true;
4,499✔
56
  _category = Command::Category::migration;
4,499✔
57
}
4,499✔
58

59
////////////////////////////////////////////////////////////////////////////////
60
int CmdSync::execute(std::string& output) {
2✔
61
  int status = 0;
2✔
62

63
  Context& context = Context::getContext();
2✔
64
  auto& replica = context.tdb2.replica();
2✔
65
  std::stringstream out;
2✔
66
  bool avoid_snapshots = false;
2✔
67
  bool verbose = Context::getContext().verbose("sync");
4✔
68

69
  std::string origin = Context::getContext().config.get("sync.server.origin");
4✔
70
  std::string url = Context::getContext().config.get("sync.server.url");
4✔
71
  std::string server_dir = Context::getContext().config.get("sync.local.server_dir");
4✔
72
  std::string client_id = Context::getContext().config.get("sync.server.client_id");
4✔
73
  std::string aws_bucket = Context::getContext().config.get("sync.aws.bucket");
4✔
74
  std::string gcp_bucket = Context::getContext().config.get("sync.gcp.bucket");
4✔
75
  std::string encryption_secret = Context::getContext().config.get("sync.encryption_secret");
4✔
76

77
  // sync.server.origin is a deprecated synonym for sync.server.url
78
  std::string server_url = url == "" ? origin : url;
2✔
79
  if (origin != "") {
2✔
80
    out << "sync.server.origin is deprecated. Use sync.server.url instead.\n";
×
81
  }
82

83
  if (server_dir != "") {
2✔
84
    if (verbose) {
2✔
85
      out << format("Syncing with {1}", server_dir) << '\n';
6✔
86
    }
87
    replica->sync_to_local(server_dir, avoid_snapshots);
2✔
88

89
    out << format("Synced with {1}", server_dir) << '\n';
6✔
90
  } else if (aws_bucket != "") {
×
91
    std::string aws_region = Context::getContext().config.get("sync.aws.region");
×
92
    std::string aws_profile = Context::getContext().config.get("sync.aws.profile");
×
93
    std::string aws_access_key_id = Context::getContext().config.get("sync.aws.access_key_id");
×
94
    std::string aws_secret_access_key =
95
        Context::getContext().config.get("sync.aws.secret_access_key");
×
96
    std::string aws_default_credentials =
97
        Context::getContext().config.get("sync.aws.default_credentials");
×
98
    if (aws_region == "") {
×
99
      throw std::string("sync.aws.region is required");
×
100
    }
101
    if (encryption_secret == "") {
×
102
      throw std::string("sync.encryption_secret is required");
×
103
    }
104

105
    bool using_profile = false;
×
106
    bool using_creds = false;
×
107
    bool using_default = false;
×
108
    if (aws_profile != "") {
×
109
      using_profile = true;
×
110
    }
111
    if (aws_access_key_id != "" || aws_secret_access_key != "") {
×
112
      using_creds = true;
×
113
    }
114
    if (aws_default_credentials != "") {
×
115
      using_default = true;
×
116
    }
117

118
    if (using_profile + using_creds + using_default != 1) {
×
119
      throw std::string("exactly one method of specifying AWS credentials is required");
×
120
    }
121

122
    if (verbose) {
×
123
      out << format("Syncing with AWS bucket {1}", aws_bucket) << '\n';
×
124
    }
125

126
    if (using_profile) {
×
127
      replica->sync_to_aws_with_profile(aws_region, aws_bucket, aws_profile, encryption_secret,
×
128
                                        avoid_snapshots);
129
    } else if (using_creds) {
×
130
      replica->sync_to_aws_with_access_key(aws_region, aws_bucket, aws_access_key_id,
×
131
                                           aws_secret_access_key, encryption_secret,
132
                                           avoid_snapshots);
133
    } else {
134
      replica->sync_to_aws_with_default_creds(aws_region, aws_bucket, encryption_secret,
×
135
                                              avoid_snapshots);
136
    }
137

NEW
138
    out << format("Synced with AWS bucket {1}", aws_bucket) << '\n';
×
139
  } else if (gcp_bucket != "") {
×
140
    std::string gcp_credential_path = Context::getContext().config.get("sync.gcp.credential_path");
×
141
    if (encryption_secret == "") {
×
142
      throw std::string("sync.encryption_secret is required");
×
143
    }
144
    if (verbose) {
×
145
      out << format("Syncing with GCP bucket {1}", gcp_bucket) << '\n';
×
146
    }
147
    replica->sync_to_gcp(gcp_bucket, gcp_credential_path, encryption_secret, avoid_snapshots);
×
148

NEW
149
    out << format("Synced with GCP bucket {1}", gcp_bucket) << '\n';
×
150
  } else if (server_url != "") {
×
151
    if (client_id == "" || encryption_secret == "") {
×
152
      throw std::string("sync.server.client_id and sync.encryption_secret are required");
×
153
    }
154
    if (verbose) {
×
155
      out << format("Syncing with sync server at {1}", server_url) << '\n';
×
156
    }
157
    replica->sync_to_remote(server_url, tc::uuid_from_string(client_id), encryption_secret,
×
158
                            avoid_snapshots);
159

NEW
160
    out << format("Synced with sync server at {1}", server_url) << '\n';
×
161
  } else {
162
    throw std::string("No sync.* settings are configured. See task-sync(5).");
×
163
  }
164

165
  if (context.config.getBoolean("purge.on-sync")) {
6✔
166
    context.tdb2.expire_tasks();
1✔
167
  }
168

169
  output = out.str();
2✔
170
  return status;
2✔
171
}
2✔
172

173
////////////////////////////////////////////////////////////////////////////////
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc