1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
*/ |
4 |
|
|
|
5 |
|
|
#include "cvmfs_config.h" |
6 |
|
|
#include "swissknife_lsrepo.h" |
7 |
|
|
|
8 |
|
|
#include <string> |
9 |
|
|
|
10 |
|
|
#include "logging.h" |
11 |
|
|
#include "util/posix.h" |
12 |
|
|
#include "util/string.h" |
13 |
|
|
|
14 |
|
|
namespace swissknife { |
15 |
|
|
|
16 |
|
|
CommandListCatalogs::CommandListCatalogs() : |
17 |
|
|
print_tree_(false), print_hash_(false), print_size_(false), |
18 |
|
|
print_entries_(false) {} |
19 |
|
|
|
20 |
|
|
|
21 |
|
|
ParameterList CommandListCatalogs::GetParams() const { |
22 |
|
|
ParameterList r; |
23 |
|
|
r.push_back(Parameter::Mandatory( |
24 |
|
|
'r', "repository URL (absolute local path or remote URL)")); |
25 |
|
|
r.push_back(Parameter::Optional('n', "fully qualified repository name")); |
26 |
|
|
r.push_back(Parameter::Optional('k', "repository master key(s) / dir")); |
27 |
|
|
r.push_back(Parameter::Optional('l', "temporary directory")); |
28 |
|
|
r.push_back(Parameter::Optional('h', "root hash (other than trunk)")); |
29 |
|
|
r.push_back(Parameter::Switch('t', "print tree structure of catalogs")); |
30 |
|
|
r.push_back(Parameter::Switch('d', "print digest for each catalog")); |
31 |
|
|
r.push_back(Parameter::Switch('s', "print catalog file sizes")); |
32 |
|
|
r.push_back(Parameter::Switch('e', "print number of catalog entries")); |
33 |
|
|
return r; |
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
|
37 |
|
|
int CommandListCatalogs::Main(const ArgumentList &args) { |
38 |
|
|
print_tree_ = (args.count('t') > 0); |
39 |
|
|
print_hash_ = (args.count('d') > 0); |
40 |
|
|
print_size_ = (args.count('s') > 0); |
41 |
|
|
print_entries_ = (args.count('e') > 0); |
42 |
|
|
|
43 |
|
|
shash::Any manual_root_hash; |
44 |
|
|
const std::string &repo_url = *args.find('r')->second; |
45 |
|
|
const std::string &repo_name = |
46 |
|
|
(args.count('n') > 0) ? *args.find('n')->second : ""; |
47 |
|
|
std::string repo_keys = |
48 |
|
|
(args.count('k') > 0) ? *args.find('k')->second : ""; |
49 |
|
|
if (DirectoryExists(repo_keys)) |
50 |
|
|
repo_keys = JoinStrings(FindFilesBySuffix(repo_keys, ".pub"), ":"); |
51 |
|
|
const std::string &tmp_dir = |
52 |
|
|
(args.count('l') > 0) ? *args.find('l')->second : "/tmp"; |
53 |
|
|
if (args.count('h') > 0) { |
54 |
|
|
manual_root_hash = shash::MkFromHexPtr(shash::HexPtr( |
55 |
|
|
*args.find('h')->second), shash::kSuffixCatalog); |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
bool success = false; |
59 |
|
|
if (IsHttpUrl(repo_url)) { |
60 |
|
|
const bool follow_redirects = false; |
61 |
|
|
if (!this->InitDownloadManager(follow_redirects) || |
62 |
|
|
!this->InitVerifyingSignatureManager(repo_keys)) { |
63 |
|
|
LogCvmfs(kLogCatalog, kLogStderr, "Failed to init remote connection"); |
64 |
|
|
return 1; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
HttpObjectFetcher<catalog::Catalog, |
68 |
|
|
history::SqliteHistory> fetcher(repo_name, |
69 |
|
|
repo_url, |
70 |
|
|
tmp_dir, |
71 |
|
|
download_manager(), |
72 |
|
|
signature_manager()); |
73 |
|
|
success = Run(manual_root_hash, &fetcher); |
74 |
|
|
} else { |
75 |
|
|
LocalObjectFetcher<> fetcher(repo_url, tmp_dir); |
76 |
|
|
success = Run(manual_root_hash, &fetcher); |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
return (success) ? 0 : 1; |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
|
83 |
|
|
void CommandListCatalogs::CatalogCallback( |
84 |
|
|
const CatalogTraversalData<catalog::Catalog> &data) { |
85 |
|
|
std::string tree_indent; |
86 |
|
|
std::string hash_string; |
87 |
|
|
std::string clg_size; |
88 |
|
|
std::string clg_entries; |
89 |
|
|
std::string path; |
90 |
|
|
|
91 |
|
|
if (print_tree_) { |
92 |
|
|
for (unsigned int i = 1; i < data.tree_level; ++i) { |
93 |
|
|
tree_indent += "\u2502 "; |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
if (data.tree_level > 0) |
97 |
|
|
tree_indent += "\u251C\u2500 "; |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
if (print_hash_) { |
101 |
|
|
hash_string = data.catalog_hash.ToString() + " "; |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
if (print_size_) { |
105 |
|
|
clg_size = StringifyInt(data.file_size) + "B "; |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
if (print_entries_) { |
109 |
|
|
clg_entries = StringifyInt(data.catalog->GetNumEntries()) + " "; |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
path = data.catalog->mountpoint().ToString(); |
113 |
|
|
if (path.empty()) |
114 |
|
|
path = "/"; |
115 |
|
|
|
116 |
|
|
LogCvmfs(kLogCatalog, kLogStdout, "%s%s%s%s%s", |
117 |
|
|
tree_indent.c_str(), hash_string.c_str(), clg_size.c_str(), |
118 |
|
|
clg_entries.c_str(), path.c_str()); |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
} // namespace swissknife |