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