GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/manifest.h
Date: 2025-07-13 02:35:07
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 331 Breadcrumb() : catalog_hash(), timestamp(0), revision(kInvalidRevision) { }
26 58 Breadcrumb(const shash::Any &h, uint64_t t, uint64_t r)
27 58 : 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 375 bool IsValid() const {
34
2/2
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 16 times.
463 return !catalog_hash.IsNull() && (timestamp > 0)
35
4/4
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 287 times.
✓ Branch 2 taken 68 times.
✓ Branch 3 taken 4 times.
463 && (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 241 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 241 : catalog_hash_(catalog_hash)
70 241 , catalog_size_(catalog_size)
71 241 , root_path_(root_path)
72 241 , ttl_(ttl)
73 241 , revision_(revision)
74 241 , micro_catalog_hash_(micro_catalog_hash)
75 241 , repository_name_(repository_name)
76 241 , certificate_(certificate)
77 241 , history_(history)
78 241 , publish_timestamp_(publish_timestamp)
79 241 , garbage_collectable_(garbage_collectable)
80 241 , has_alt_catalog_path_(has_alt_catalog_path)
81 241 , meta_info_(meta_info)
82 241 , 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 660 shash::Algorithms GetHashAlgorithm() const { return catalog_hash_.algorithm; }
91
92 612 void set_ttl(const uint32_t ttl) { ttl_ = ttl; }
93 612 void set_revision(const uint64_t revision) { revision_ = revision; }
94 828 void set_certificate(const shash::Any &certificate) {
95 828 certificate_ = certificate;
96 828 }
97 5609 void set_history(const shash::Any &history_db) { history_ = history_db; }
98 837 void set_repository_name(const std::string &repository_name) {
99 837 repository_name_ = repository_name;
100 837 }
101 617 void set_publish_timestamp(const uint32_t publish_timestamp) {
102 617 publish_timestamp_ = publish_timestamp;
103 617 }
104 612 void set_catalog_size(const uint64_t catalog_size) {
105 612 catalog_size_ = catalog_size;
106 612 }
107 612 void set_catalog_hash(const shash::Any &catalog_hash) {
108 612 catalog_hash_ = catalog_hash;
109 612 }
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 612 void set_root_path(const std::string &root_path) {
118
1/2
✓ Branch 2 taken 612 times.
✗ Branch 3 not taken.
612 root_path_ = shash::Md5(shash::AsciiPtr(root_path));
119 612 }
120 void set_reflog_hash(const shash::Any &checksum) { reflog_hash_ = checksum; }
121
122 124 uint64_t revision() const { return revision_; }
123 178 std::string repository_name() const { return repository_name_; }
124 146 shash::Md5 root_path() const { return root_path_; }
125 5337 shash::Any catalog_hash() const { return catalog_hash_; }
126 uint64_t catalog_size() const { return catalog_size_; }
127 168 shash::Any certificate() const { return certificate_; }
128 4114 shash::Any history() const { return history_; }
129 155 uint64_t publish_timestamp() const { return publish_timestamp_; }
130 bool garbage_collectable() const { return garbage_collectable_; }
131 40 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 133 std::string MakeCertificatePath() const {
141 133 return has_alt_catalog_path_ ? certificate_.MakeAlternativePath()
142
4/13
✗ Branch 0 not taken.
✓ Branch 1 taken 133 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 133 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 133 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 133 times.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
266 : ("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