GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/swissknife_main.cc
Date: 2026-10-04 02:40:33
Exec Total Coverage
Lines: 0 114 0.0%
Branches: 0 68 0.0%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5 #include <cassert>
6 #include <string>
7
8 #include "swissknife.h"
9 #include "swissknife_check.h"
10 #include "swissknife_filestats.h"
11 #include "swissknife_gc.h"
12 #include "swissknife_graft.h"
13 #include "swissknife_history.h"
14 #include "swissknife_info.h"
15 #include "swissknife_ingest.h"
16 #include "swissknife_ingestsql.h"
17 #include "swissknife_lease.h"
18 #include "swissknife_letter.h"
19 #include "swissknife_list_reflog.h"
20 #include "swissknife_lsrepo.h"
21 #include "swissknife_migrate.h"
22 #include "swissknife_notify.h"
23 #include "swissknife_overlay.h"
24 #include "swissknife_pull.h"
25 #include "swissknife_reflog.h"
26 #include "swissknife_rotate_statsdb.h"
27 #include "swissknife_scrub.h"
28 #include "swissknife_sign.h"
29 #include "swissknife_sync.h"
30 #include "swissknife_zpipe.h"
31 #include "util/logging.h"
32 #include "util/posix.h" // IWYU pragma: keep
33 #include "util/string.h"
34
35 using namespace std; // NOLINT
36
37 typedef vector<swissknife::Command *> Commands;
38 Commands command_list;
39
40 ✗ void Usage() {
41 ✗ LogCvmfs(kLogCvmfs, kLogStdout,
42 "CernVM-FS repository storage management commands\n"
43 "Usage (normally called from cvmfs_server):\n"
44 " cvmfs_swissknife <command> [options]\n");
45
46 ✗ for (unsigned i = 0; i < command_list.size(); ++i) {
47 ✗ LogCvmfs(kLogCvmfs, kLogStdout | kLogNoLinebreak,
48 "\n"
49 "Command %s\n"
50 "--",
51 command_list[i]->GetName().c_str());
52 ✗ LogCvmfs(kLogCvmfs, kLogStdout | kLogNoLinebreak, "\n");
53 ✗ LogCvmfs(kLogCvmfs, kLogStdout, "%s",
54 command_list[i]->GetDescription().c_str());
55 ✗ swissknife::ParameterList params = command_list[i]->GetParams();
56 ✗ if (!params.empty()) {
57 ✗ LogCvmfs(kLogCvmfs, kLogStdout, "Options:");
58 ✗ for (unsigned j = 0; j < params.size(); ++j) {
59 ✗ LogCvmfs(kLogCvmfs, kLogStdout | kLogNoLinebreak, " -%c %s",
60 params[j].key(), params[j].description().c_str());
61 ✗ if (params[j].optional())
62 ✗ LogCvmfs(kLogCvmfs, kLogStdout | kLogNoLinebreak, " (optional)");
63 ✗ LogCvmfs(kLogCvmfs, kLogStdout | kLogNoLinebreak, "\n");
64 }
65 } // Parameter list
66 ✗ } // Command list
67
68 ✗ LogCvmfs(kLogCvmfs, kLogStdout | kLogNoLinebreak, "\n");
69 }
70
71
72 ✗ int main(int argc, char **argv) {
73 // Set default logging facilities
74 ✗ DefaultLogging::Set(kLogStdout, kLogStderr);
75
76 ✗ command_list.push_back(new swissknife::CommandCreate());
77 ✗ command_list.push_back(new swissknife::CommandUpload());
78 ✗ command_list.push_back(new swissknife::CommandRemove());
79 ✗ command_list.push_back(new swissknife::CommandPeek());
80 ✗ command_list.push_back(new swissknife::CommandSync());
81 ✗ command_list.push_back(new swissknife::CommandApplyDirtab());
82 ✗ command_list.push_back(new swissknife::CommandEditTag());
83 ✗ command_list.push_back(new swissknife::CommandListTags());
84 ✗ command_list.push_back(new swissknife::CommandInfoTag());
85 ✗ command_list.push_back(new swissknife::CommandRollbackTag());
86 ✗ command_list.push_back(new swissknife::CommandEmptyRecycleBin());
87 ✗ command_list.push_back(new swissknife::CommandSign());
88 ✗ command_list.push_back(new swissknife::CommandLetter());
89 ✗ command_list.push_back(new swissknife::CommandCheck());
90 ✗ command_list.push_back(new swissknife::CommandListCatalogs());
91 ✗ command_list.push_back(new swissknife::CommandPull());
92 ✗ command_list.push_back(new swissknife::CommandZpipe());
93 ✗ command_list.push_back(new swissknife::CommandGraft());
94 ✗ command_list.push_back(new swissknife::CommandInfo());
95 ✗ command_list.push_back(new swissknife::CommandVersion());
96 ✗ command_list.push_back(new swissknife::CommandMigrate());
97 ✗ command_list.push_back(new swissknife::CommandScrub());
98 ✗ command_list.push_back(new swissknife::CommandGc());
99 ✗ command_list.push_back(new swissknife::CommandListReflog());
100 ✗ command_list.push_back(new swissknife::CommandReconstructReflog());
101 ✗ command_list.push_back(new swissknife::CommandLease());
102 ✗ command_list.push_back(new swissknife::Ingest());
103 ✗ command_list.push_back(new swissknife::IngestSQL());
104 ✗ command_list.push_back(new swissknife::CommandNotify());
105 ✗ command_list.push_back(new swissknife::CommandOverlay());
106 ✗ command_list.push_back(new swissknife::CommandFileStats());
107 ✗ command_list.push_back(new swissknife::CommandRotateStatsDB());
108
109 ✗ if (argc < 2) {
110 ✗ Usage();
111 ✗ return 1;
112 }
113 ✗ if ((string(argv[1]) == "--help")) {
114 ✗ Usage();
115 ✗ return 0;
116 }
117 ✗ if ((string(argv[1]) == "--version")) {
118 ✗ swissknife::CommandVersion().Main(swissknife::ArgumentList());
119 ✗ return 0;
120 }
121
122 // find the command to be run
123 ✗ swissknife::Command *command = NULL;
124 ✗ for (unsigned i = 0; i < command_list.size(); ++i) {
125 ✗ if (command_list[i]->GetName() == string(argv[1])) {
126 ✗ command = command_list[i];
127 ✗ break;
128 }
129 }
130
131 ✗ if (NULL == command) {
132 ✗ Usage();
133 ✗ return 1;
134 }
135
136 ✗ bool display_statistics = false;
137
138 // parse the command line arguments for the Command
139 ✗ swissknife::ArgumentList args;
140 ✗ optind = 1;
141 ✗ string option_string = "";
142 ✗ swissknife::ParameterList params = command->GetParams();
143 ✗ for (unsigned j = 0; j < params.size(); ++j) {
144 ✗ option_string.push_back(params[j].key());
145 ✗ if (!params[j].switch_only())
146 ✗ option_string.push_back(':');
147 }
148 // Now adding the generic -+ extra option command
149 ✗ option_string.push_back(swissknife::Command::kGenericParam);
150 ✗ option_string.push_back(':');
151 int c;
152 ✗ while ((c = getopt(argc, argv, option_string.c_str())) != -1) {
153 ✗ bool valid_option = false;
154 ✗ for (unsigned j = 0; j < params.size(); ++j) {
155 ✗ if (c == params[j].key()) {
156 ✗ assert(c != swissknife::Command::kGenericParam);
157 ✗ valid_option = true;
158 ✗ args[c].Reset();
159 ✗ if (!params[j].switch_only()) {
160 ✗ args[c].Reset(new string(optarg));
161 }
162 ✗ break;
163 }
164 }
165 ✗ if (c == swissknife::Command::kGenericParam) {
166 ✗ valid_option = true;
167 vector<string> flags = SplitString(
168 ✗ optarg, swissknife::Command::kGenericParamSeparator);
169 ✗ for (unsigned i = 0; i < flags.size(); ++i) {
170 ✗ if (flags[i] == "stats") {
171 ✗ display_statistics = true;
172 }
173 }
174 }
175 ✗ if (!valid_option) {
176 ✗ Usage();
177 ✗ return 1;
178 }
179 }
180 ✗ for (unsigned j = 0; j < params.size(); ++j) {
181 ✗ if (!params[j].optional()) {
182 ✗ if (args.find(params[j].key()) == args.end()) {
183 ✗ LogCvmfs(kLogCvmfs, kLogStderr, "parameter -%c missing",
184 params[j].key());
185 ✗ return 1;
186 }
187 }
188 }
189
190 // run the command
191 ✗ const string start_time = GetGMTimestamp();
192 ✗ const int retval = command->Main(args);
193 ✗ const string finish_time = GetGMTimestamp();
194
195 ✗ if (display_statistics) {
196 ✗ LogCvmfs(kLogCvmfs, kLogStdout, "Command statistics");
197 ✗ LogCvmfs(kLogCvmfs, kLogStdout, "%s",
198 command->statistics()
199 ->PrintList(perf::Statistics::kPrintHeader)
200 .c_str());
201 }
202
203 // delete the command list
204 ✗ Commands::const_iterator i = command_list.begin();
205 ✗ const Commands::const_iterator iend = command_list.end();
206 ✗ for (; i != iend; ++i) {
207 ✗ delete *i;
208 }
209 ✗ command_list.clear();
210
211 ✗ return retval;
212 }
213