GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/swissknife_main.cc
Date: 2026-03-15 02:35:27
Exec Total Coverage
Lines: 0 113 0.0%
Branches: 0 54 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 "statistics_database.h"
9 #include "swissknife.h"
10 #include "swissknife_check.h"
11 #include "swissknife_filestats.h"
12 #include "swissknife_gc.h"
13 #include "swissknife_graft.h"
14 #include "swissknife_history.h"
15 #include "swissknife_info.h"
16 #include "swissknife_ingest.h"
17 #include "swissknife_ingestsql.h"
18 #include "swissknife_lease.h"
19 #include "swissknife_letter.h"
20 #include "swissknife_list_reflog.h"
21 #include "swissknife_lsrepo.h"
22 #include "swissknife_migrate.h"
23 #include "swissknife_notify.h"
24 #include "swissknife_overlay.h"
25 #include "swissknife_pull.h"
26 #include "swissknife_reflog.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"
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
108 if (argc < 2) {
109 Usage();
110 return 1;
111 }
112 if ((string(argv[1]) == "--help")) {
113 Usage();
114 return 0;
115 }
116 if ((string(argv[1]) == "--version")) {
117 swissknife::CommandVersion().Main(swissknife::ArgumentList());
118 return 0;
119 }
120
121 // find the command to be run
122 swissknife::Command *command = NULL;
123 for (unsigned i = 0; i < command_list.size(); ++i) {
124 if (command_list[i]->GetName() == string(argv[1])) {
125 command = command_list[i];
126 break;
127 }
128 }
129
130 if (NULL == command) {
131 Usage();
132 return 1;
133 }
134
135 bool display_statistics = false;
136
137 // parse the command line arguments for the Command
138 swissknife::ArgumentList args;
139 optind = 1;
140 string option_string = "";
141 swissknife::ParameterList params = command->GetParams();
142 for (unsigned j = 0; j < params.size(); ++j) {
143 option_string.push_back(params[j].key());
144 if (!params[j].switch_only())
145 option_string.push_back(':');
146 }
147 // Now adding the generic -+ extra option command
148 option_string.push_back(swissknife::Command::kGenericParam);
149 option_string.push_back(':');
150 int c;
151 while ((c = getopt(argc, argv, option_string.c_str())) != -1) {
152 bool valid_option = false;
153 for (unsigned j = 0; j < params.size(); ++j) {
154 if (c == params[j].key()) {
155 assert(c != swissknife::Command::kGenericParam);
156 valid_option = true;
157 args[c].Reset();
158 if (!params[j].switch_only()) {
159 args[c].Reset(new string(optarg));
160 }
161 break;
162 }
163 }
164 if (c == swissknife::Command::kGenericParam) {
165 valid_option = true;
166 vector<string> flags = SplitString(
167 optarg, swissknife::Command::kGenericParamSeparator);
168 for (unsigned i = 0; i < flags.size(); ++i) {
169 if (flags[i] == "stats") {
170 display_statistics = true;
171 }
172 }
173 }
174 if (!valid_option) {
175 Usage();
176 return 1;
177 }
178 }
179 for (unsigned j = 0; j < params.size(); ++j) {
180 if (!params[j].optional()) {
181 if (args.find(params[j].key()) == args.end()) {
182 LogCvmfs(kLogCvmfs, kLogStderr, "parameter -%c missing",
183 params[j].key());
184 return 1;
185 }
186 }
187 }
188
189 // run the command
190 const string start_time = GetGMTimestamp();
191 const int retval = command->Main(args);
192 const string finish_time = GetGMTimestamp();
193
194 if (display_statistics) {
195 LogCvmfs(kLogCvmfs, kLogStdout, "Command statistics");
196 LogCvmfs(kLogCvmfs, kLogStdout, "%s",
197 command->statistics()
198 ->PrintList(perf::Statistics::kPrintHeader)
199 .c_str());
200 }
201
202 // delete the command list
203 Commands::const_iterator i = command_list.begin();
204 const Commands::const_iterator iend = command_list.end();
205 for (; i != iend; ++i) {
206 delete *i;
207 }
208 command_list.clear();
209
210 return retval;
211 }
212