GCC Code Coverage Report


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