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

GothenburgBitFactory / taskwarrior / 9800779936

04 Jul 2024 11:17PM UTC coverage: 84.081% (-0.1%) from 84.211%
9800779936

push

github

web-flow
Relax sync.server.origin to allow paths (#3423)

0 of 13 new or added lines in 2 files covered. (0.0%)

28 existing lines in 2 files now uncovered.

19221 of 22860 relevant lines covered (84.08%)

20051.8 hits per line

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

24.53
/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
#include <CmdSync.h>
29
#include <sstream>
30
#include <inttypes.h>
31
#include <signal.h>
32
#include <Context.h>
33
#include <Filter.h>
34
#include <Color.h>
35
#include <shared.h>
36
#include <format.h>
37
#include <util.h>
38
#include "tc/Server.h"
39

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

56
////////////////////////////////////////////////////////////////////////////////
57
int CmdSync::execute (std::string& output)
×
58
{
59
  int status = 0;
×
60

61
  tc::Server server;
×
62
  std::string server_ident;
×
63

64
  // If no server is set up, quit.
65
  std::string origin = Context::getContext ().config.get ("sync.server.origin");
×
NEW
66
  std::string url = Context::getContext ().config.get ("sync.server.url");
×
67
  std::string server_dir = Context::getContext ().config.get ("sync.local.server_dir");
×
68
  std::string gcp_credential_path = Context::getContext ().config.get ("sync.gcp.credential_path");
×
69
  std::string gcp_bucket = Context::getContext ().config.get ("sync.gcp.bucket");
×
70
  std::string encryption_secret = Context::getContext ().config.get ("sync.encryption_secret");
×
71

72
  // sync.server.origin is a deprecated synonym for sync.server.url
NEW
73
  std::string server_url = url == "" ? origin : url;
×
74

75
  if (server_dir != "") {
×
76
    server = tc::Server::new_local (server_dir);
×
77
    server_ident = server_dir;
×
78
  } else if (gcp_bucket != "") {
×
79
    if (encryption_secret == "") {
×
80
      throw std::string ("sync.encryption_secret is required");
×
81
    }
82
    server = tc::Server::new_gcp (gcp_bucket, gcp_credential_path, encryption_secret);
×
83
    std::ostringstream os;
×
84
    os << "GCP bucket " << gcp_bucket;
×
85
    server_ident = os.str();
×
NEW
86
  } else if (server_url != "") {
×
87
    std::string client_id = Context::getContext ().config.get ("sync.server.client_id");
×
88
    if (client_id == "" || encryption_secret == "") {
×
89
      throw std::string ("sync.server.client_id and sync.encryption_secret are required");
×
90
    }
NEW
91
    server = tc::Server::new_sync (server_url, client_id, encryption_secret);
×
92
    std::ostringstream os;
×
NEW
93
    os << "Sync server at " << server_url;
×
94
    server_ident = os.str();
×
95
  } else {
×
96
    throw std::string ("No sync.* settings are configured. See task-sync(5).");
×
97
  }
98

99
  std::stringstream out;
×
NEW
100
  if (origin != "") {
×
NEW
101
    out << "sync.server.origin is deprecated. Use sync.server.url instead.\n";
×
102
  }
103

NEW
104
  if (Context::getContext ().verbose ("sync")) {
×
105
    out << format ("Syncing with {1}", server_ident)
×
106
        << '\n';
×
107
  }
108

109
  Context::getContext ().tdb2.sync(std::move(server), false);
×
110

111
  output = out.str ();
×
112
  return status;
×
113
}
114

115
////////////////////////////////////////////////////////////////////////////////
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