GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/swissknife_lsrepo.cc
Date: 2024-04-21 02:33:16
Exec Total Coverage
Lines: 0 67 0.0%
Branches: 0 46 0.0%

Line Branch Exec Source
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 "util/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::Optional('@', "proxy url"));
30 r.push_back(Parameter::Switch('t', "print tree structure of catalogs"));
31 r.push_back(Parameter::Switch('d', "print digest for each catalog"));
32 r.push_back(Parameter::Switch('s', "print catalog file sizes"));
33 r.push_back(Parameter::Switch('e', "print number of catalog entries"));
34 return r;
35 }
36
37
38 int CommandListCatalogs::Main(const ArgumentList &args) {
39 print_tree_ = (args.count('t') > 0);
40 print_hash_ = (args.count('d') > 0);
41 print_size_ = (args.count('s') > 0);
42 print_entries_ = (args.count('e') > 0);
43
44 shash::Any manual_root_hash;
45 const std::string &repo_url = *args.find('r')->second;
46 const std::string &repo_name =
47 (args.count('n') > 0) ? *args.find('n')->second : "";
48 std::string repo_keys =
49 (args.count('k') > 0) ? *args.find('k')->second : "";
50 if (DirectoryExists(repo_keys))
51 repo_keys = JoinStrings(FindFilesBySuffix(repo_keys, ".pub"), ":");
52 const std::string &tmp_dir =
53 (args.count('l') > 0) ? *args.find('l')->second : "/tmp";
54 if (args.count('h') > 0) {
55 manual_root_hash = shash::MkFromHexPtr(shash::HexPtr(
56 *args.find('h')->second), shash::kSuffixCatalog);
57 }
58
59 bool success = false;
60 if (IsHttpUrl(repo_url)) {
61 const bool follow_redirects = false;
62 const std::string proxy = ((args.count('@') > 0) ?
63 *args.find('@')->second : "");
64 if (!this->InitDownloadManager(follow_redirects, proxy) ||
65 !this->InitVerifyingSignatureManager(repo_keys)) {
66 LogCvmfs(kLogCatalog, kLogStderr, "Failed to init remote connection");
67 return 1;
68 }
69
70 HttpObjectFetcher<catalog::Catalog,
71 history::SqliteHistory> fetcher(repo_name,
72 repo_url,
73 tmp_dir,
74 download_manager(),
75 signature_manager());
76 success = Run(manual_root_hash, &fetcher);
77 } else {
78 LocalObjectFetcher<> fetcher(repo_url, tmp_dir);
79 success = Run(manual_root_hash, &fetcher);
80 }
81
82 return (success) ? 0 : 1;
83 }
84
85
86 void CommandListCatalogs::CatalogCallback(
87 const CatalogTraversalData<catalog::Catalog> &data) {
88 std::string tree_indent;
89 std::string hash_string;
90 std::string clg_size;
91 std::string clg_entries;
92 std::string path;
93
94 if (print_tree_) {
95 for (unsigned int i = 1; i < data.tree_level; ++i) {
96 tree_indent += "\u2502 ";
97 }
98
99 if (data.tree_level > 0)
100 tree_indent += "\u251C\u2500 ";
101 }
102
103 if (print_hash_) {
104 hash_string = data.catalog_hash.ToString() + " ";
105 }
106
107 if (print_size_) {
108 clg_size = StringifyInt(data.file_size) + "B ";
109 }
110
111 if (print_entries_) {
112 clg_entries = StringifyInt(data.catalog->GetNumEntries()) + " ";
113 }
114
115 path = data.catalog->mountpoint().ToString();
116 if (path.empty())
117 path = "/";
118
119 LogCvmfs(kLogCatalog, kLogStdout, "%s%s%s%s%s",
120 tree_indent.c_str(), hash_string.c_str(), clg_size.c_str(),
121 clg_entries.c_str(), path.c_str());
122 }
123
124 } // namespace swissknife
125