GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/manifest.h
Date: 2025-06-22 02:36:02
Exec Total Coverage
Lines: 54 64 84.4%
Branches: 11 21 52.4%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5 #ifndef CVMFS_MANIFEST_H_
6 #define CVMFS_MANIFEST_H_
7
8 #include <stdint.h>
9
10 #include <map>
11 #include <string>
12
13 #include "crypto/hash.h"
14 #include "history.h"
15
16 namespace manifest {
17
18 /**
19 * The breadcrumb stores the catalog root hash, its revision and a time stamp.
20 * It is used to store the last known copy of the catalog in the cache.
21 */
22 struct Breadcrumb {
23 static const uint64_t kInvalidRevision = -1ul;
24
25 1669 Breadcrumb() : catalog_hash(), timestamp(0), revision(kInvalidRevision) { }
26 467 Breadcrumb(const shash::Any &h, uint64_t t, uint64_t r)
27 467 : catalog_hash(h), timestamp(t), revision(r) { }
28 explicit Breadcrumb(const std::string &from_string);
29
30 bool Export(const std::string &fqrn, const std::string &directory,
31 const int mode) const;
32 std::string ToString() const;
33 1943 bool IsValid() const {
34
2/2
✓ Branch 1 taken 416 times.
✓ Branch 2 taken 60 times.
2419 return !catalog_hash.IsNull() && (timestamp > 0)
35
4/4
✓ Branch 0 taken 476 times.
✓ Branch 1 taken 1467 times.
✓ Branch 2 taken 401 times.
✓ Branch 3 taken 15 times.
2419 && (revision != kInvalidRevision);
36 }
37
38 shash::Any catalog_hash;
39 uint64_t timestamp;
40 uint64_t revision;
41 };
42
43
44 /**
45 * The Manifest is the bootstrap snippet for a repository. It is stored in
46 * .cvmfspublished.
47 */
48 class Manifest {
49 public:
50 static Manifest *LoadFile(const std::string &path);
51 static Manifest *LoadMem(const unsigned char *buffer, const unsigned length);
52 Manifest(const shash::Any &catalog_hash,
53 const uint64_t catalog_size,
54 const std::string &root_path);
55 1324 Manifest(const shash::Any &catalog_hash,
56 const uint64_t catalog_size,
57 const shash::Md5 &root_path,
58 const uint32_t ttl,
59 const uint64_t revision,
60 const shash::Any &micro_catalog_hash,
61 const std::string &repository_name,
62 const shash::Any certificate,
63 const shash::Any history,
64 const uint64_t publish_timestamp,
65 const bool garbage_collectable,
66 const bool has_alt_catalog_path,
67 const shash::Any &meta_info,
68 const shash::Any &reflog_hash)
69 1324 : catalog_hash_(catalog_hash)
70 1324 , catalog_size_(catalog_size)
71 1324 , root_path_(root_path)
72 1324 , ttl_(ttl)
73 1324 , revision_(revision)
74 1324 , micro_catalog_hash_(micro_catalog_hash)
75 1324 , repository_name_(repository_name)
76 1324 , certificate_(certificate)
77 1324 , history_(history)
78 1324 , publish_timestamp_(publish_timestamp)
79 1324 , garbage_collectable_(garbage_collectable)
80 1324 , has_alt_catalog_path_(has_alt_catalog_path)
81 1324 , meta_info_(meta_info)
82 1324 , reflog_hash_(reflog_hash) { }
83
84 std::string ExportString() const;
85 bool Export(const std::string &path) const;
86 bool ExportBreadcrumb(const std::string &directory, const int mode) const;
87 static Breadcrumb ReadBreadcrumb(const std::string &repo_name,
88 const std::string &directory);
89
90 1153 shash::Algorithms GetHashAlgorithm() const { return catalog_hash_.algorithm; }
91
92 863 void set_ttl(const uint32_t ttl) { ttl_ = ttl; }
93 863 void set_revision(const uint64_t revision) { revision_ = revision; }
94 1591 void set_certificate(const shash::Any &certificate) {
95 1591 certificate_ = certificate;
96 1591 }
97 5360 void set_history(const shash::Any &history_db) { history_ = history_db; }
98 1608 void set_repository_name(const std::string &repository_name) {
99 1608 repository_name_ = repository_name;
100 1608 }
101 978 void set_publish_timestamp(const uint32_t publish_timestamp) {
102 978 publish_timestamp_ = publish_timestamp;
103 978 }
104 863 void set_catalog_size(const uint64_t catalog_size) {
105 863 catalog_size_ = catalog_size;
106 863 }
107 863 void set_catalog_hash(const shash::Any &catalog_hash) {
108 863 catalog_hash_ = catalog_hash;
109 863 }
110 void set_garbage_collectability(const bool garbage_collectable) {
111 garbage_collectable_ = garbage_collectable;
112 }
113 void set_has_alt_catalog_path(const bool &has_alt_path) {
114 has_alt_catalog_path_ = has_alt_path;
115 }
116 void set_meta_info(const shash::Any &meta_info) { meta_info_ = meta_info; }
117 863 void set_root_path(const std::string &root_path) {
118
1/2
✓ Branch 2 taken 863 times.
✗ Branch 3 not taken.
863 root_path_ = shash::Md5(shash::AsciiPtr(root_path));
119 863 }
120 void set_reflog_hash(const shash::Any &checksum) { reflog_hash_ = checksum; }
121
122 1098 uint64_t revision() const { return revision_; }
123 1338 std::string repository_name() const { return repository_name_; }
124 1079 shash::Md5 root_path() const { return root_path_; }
125 7330 shash::Any catalog_hash() const { return catalog_hash_; }
126 uint64_t catalog_size() const { return catalog_size_; }
127 1322 shash::Any certificate() const { return certificate_; }
128 3896 shash::Any history() const { return history_; }
129 1096 uint64_t publish_timestamp() const { return publish_timestamp_; }
130 bool garbage_collectable() const { return garbage_collectable_; }
131 394 bool has_alt_catalog_path() const { return has_alt_catalog_path_; }
132 shash::Any meta_info() const { return meta_info_; }
133 shash::Any reflog_hash() const { return reflog_hash_; }
134
135 std::string MakeCatalogPath() const {
136 return has_alt_catalog_path_ ? catalog_hash_.MakeAlternativePath()
137 : ("data/" + catalog_hash_.MakePath());
138 }
139
140 978 std::string MakeCertificatePath() const {
141 978 return has_alt_catalog_path_ ? certificate_.MakeAlternativePath()
142
4/13
✗ Branch 0 not taken.
✓ Branch 1 taken 978 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 978 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 978 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 978 times.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
1956 : ("data/" + certificate_.MakePath());
143 }
144
145 private:
146 static Manifest *Load(const std::map<char, std::string> &content);
147 shash::Any catalog_hash_;
148 uint64_t catalog_size_;
149 shash::Md5 root_path_;
150 uint32_t ttl_;
151 uint64_t revision_;
152 shash::Any micro_catalog_hash_;
153 std::string repository_name_;
154 shash::Any certificate_;
155 shash::Any history_;
156 uint64_t publish_timestamp_;
157 bool garbage_collectable_;
158
159 /**
160 * The root catalog and the certificate might be available as .cvmfscatalog
161 * and .cvmfscertificate. That is helpful if the data subdirectory is
162 * protected on the web server.
163 */
164 bool has_alt_catalog_path_;
165
166 /**
167 * Hash of a JSON object that describes the repository (owner, purpose, list
168 * of recommended stratum 1s, ...)
169 */
170 shash::Any meta_info_;
171
172 /**
173 * Hash of the reflog file
174 */
175 shash::Any reflog_hash_;
176 }; // class Manifest
177
178 } // namespace manifest
179
180 #endif // CVMFS_MANIFEST_H_
181