GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/catalog_mgr_client.cc
Date: 2026-05-24 02:35:55
Exec Total Coverage
Lines: 211 232 90.9%
Branches: 185 323 57.3%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM file system.
3 */
4
5
6 #include "catalog_mgr_client.h"
7
8 #include <string>
9 #include <vector>
10
11 #include "cache_posix.h"
12 #include "crypto/signature.h"
13 #include "fetch.h"
14 #include "manifest.h"
15 #include "mountpoint.h"
16 #include "quota.h"
17 #include "statistics.h"
18 #include "util/posix.h" // IWYU pragma: keep
19 #include "util/string.h"
20
21 using namespace std; // NOLINT
22
23 namespace catalog {
24
25 /**
26 * Triggered when the catalog is attached (db file opened)
27 */
28 723 void ClientCatalogManager::ActivateCatalog(Catalog *catalog) {
29 const Counters &counters = const_cast<const Catalog *>(catalog)
30 723 ->GetCounters();
31
2/2
✓ Branch 1 taken 621 times.
✓ Branch 2 taken 102 times.
723 if (catalog->IsRoot()) {
32 621 all_inodes_ = counters.GetAllEntries();
33 }
34 723 loaded_inodes_ += counters.GetSelfEntries();
35 723 }
36
37
38 857 ClientCatalogManager::ClientCatalogManager(MountPoint *mountpoint)
39 : AbstractCatalogManager<Catalog>(mountpoint->statistics())
40
1/2
✓ Branch 1 taken 857 times.
✗ Branch 2 not taken.
857 , repo_name_(mountpoint->fqrn())
41 857 , fetcher_(mountpoint->fetcher())
42 857 , signature_mgr_(mountpoint->signature_mgr())
43
1/2
✓ Branch 2 taken 857 times.
✗ Branch 3 not taken.
857 , workspace_(mountpoint->file_system()->workspace())
44 857 , offline_mode_(false)
45 857 , all_inodes_(0)
46 857 , loaded_inodes_(0)
47
1/2
✓ Branch 1 taken 857 times.
✗ Branch 2 not taken.
857 , fixed_root_catalog_()
48 857 , fixed_alt_root_catalog_(false)
49
2/4
✓ Branch 5 taken 857 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 857 times.
✗ Branch 9 not taken.
1714 , root_fd_(-1) {
50
1/2
✓ Branch 1 taken 857 times.
✗ Branch 2 not taken.
857 LogCvmfs(kLogCatalog, kLogDebug, "constructing client catalog manager");
51
3/6
✓ Branch 3 taken 857 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 857 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 857 times.
✗ Branch 11 not taken.
857 n_certificate_hits_ = mountpoint->statistics()->Register(
52 "cache.n_certificate_hits", "Number of certificate hits");
53
3/6
✓ Branch 3 taken 857 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 857 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 857 times.
✗ Branch 11 not taken.
857 n_certificate_misses_ = mountpoint->statistics()->Register(
54 "cache.n_certificate_misses", "Number of certificate misses");
55 857 }
56
57
58 3428 ClientCatalogManager::~ClientCatalogManager() {
59 1714 LogCvmfs(kLogCache, kLogDebug, "unpinning / unloading all catalogs");
60
61 3428 for (map<PathString, shash::Any>::iterator i = mounted_catalogs_.begin(),
62 1714 iend = mounted_catalogs_.end();
63
2/2
✓ Branch 1 taken 721 times.
✓ Branch 2 taken 857 times.
3156 i != iend;
64 1442 ++i) {
65 1442 fetcher_->cache_mgr()->quota_mgr()->Unpin(i->second);
66 }
67 3428 }
68
69
70 723 Catalog *ClientCatalogManager::CreateCatalog(const PathString &mountpoint,
71 const shash::Any &catalog_hash,
72 catalog::Catalog *parent_catalog) {
73 723 mounted_catalogs_[mountpoint] = loaded_catalogs_[mountpoint];
74 723 loaded_catalogs_.erase(mountpoint);
75
1/2
✓ Branch 2 taken 723 times.
✗ Branch 3 not taken.
723 return new Catalog(mountpoint, catalog_hash, parent_catalog);
76 }
77
78
79 102 shash::Any ClientCatalogManager::GetRootHash() {
80 102 ReadLock();
81
1/2
✓ Branch 2 taken 102 times.
✗ Branch 3 not taken.
102 shash::Any result = mounted_catalogs_[PathString("", 0)];
82 102 Unlock();
83 102 return result;
84 }
85
86
87 /**
88 * Specialized initialization that uses a fixed root hash.
89 *
90 * @returns true - root catalog was successfully mounted
91 * false - otherwise
92 */
93 433 bool ClientCatalogManager::InitFixed(const shash::Any &root_hash,
94 bool alternative_path) {
95
1/2
✓ Branch 2 taken 433 times.
✗ Branch 3 not taken.
433 LogCvmfs(kLogCatalog, kLogDebug, "Initialize catalog with fixed root hash %s",
96 866 root_hash.ToString().c_str());
97 433 WriteLock();
98 433 fixed_alt_root_catalog_ = alternative_path;
99 433 fixed_root_catalog_ = root_hash;
100
101
1/2
✓ Branch 2 taken 433 times.
✗ Branch 3 not taken.
433 const bool attached = MountCatalog(PathString("", 0), root_hash, NULL);
102 433 Unlock();
103
104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 433 times.
433 if (!attached) {
105 LogCvmfs(kLogCatalog, kLogDebug, "failed to initialize fixed root catalog");
106 }
107
108 433 return attached;
109 }
110
111 /**
112 * Gets information about the most recent root catalog, including even if it is
113 * a fixed root catalog. This is needed as Remount() does not know what kind of
114 * root catalog will be remounted.
115 *
116 * Checks the locations: mounted, alien cache and remote (server) and sets the
117 * fields of variable "result". For the most recent catalog the location, hash
118 * and revision number are set.
119 *
120 *
121 * @param [out] result All fields but sqlite_path will be set:
122 * mountpoint, root_ctl_location, root_ctlg_revision, hash
123 * @return kLoadUp2Date - if most recent root catalog is already mounted
124 * kLoadNew - otherwise
125 */
126 355 LoadReturn ClientCatalogManager::GetNewRootCatalogContext(
127 CatalogContext *result) {
128
2/4
✓ Branch 1 taken 355 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 355 times.
✗ Branch 5 not taken.
355 result->SetMountpoint(PathString("", 0));
129
130 // quick escape if we have a fixed catalog
131
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 355 times.
355 if (!fixed_root_catalog_.IsNull()) {
132 result->SetHash(fixed_root_catalog_);
133 result->SetRootCtlgRevision(GetRevisionNoLock());
134
135 // it might or might not be already mounted, but we do not care
136 // as we do no need to download and save the manifest
137 // (see LoadCatalogByHash()) as such we must set the location to this
138 result->SetRootCtlgLocation(kCtlgLocationMounted);
139 offline_mode_ = false;
140
141 // we can do this here as the very first time fixed catalog is loaded it
142 // call directly MountCatalog() and will skip the call to this function
143 // here
144 return catalog::kLoadUp2Date;
145 }
146
147 // 1) Get alien cache root catalog (local)
148
149 // Happens only on init/remount, i.e. quota won't delete a cached catalog
150
1/2
✓ Branch 1 taken 355 times.
✗ Branch 2 not taken.
355 shash::Any local_newest_hash(shash::kSha1, shash::kSuffixCatalog);
151
1/2
✓ Branch 1 taken 355 times.
✗ Branch 2 not taken.
355 shash::Any mounted_hash(shash::kSha1, shash::kSuffixCatalog);
152 355 uint64_t local_newest_timestamp = 0;
153 355 uint64_t local_newest_revision = manifest::Breadcrumb::kInvalidRevision;
154
155 355 const manifest::Breadcrumb breadcrumb = fetcher_->cache_mgr()->LoadBreadcrumb(
156
1/2
✓ Branch 1 taken 355 times.
✗ Branch 2 not taken.
355 repo_name_);
157
3/4
✓ Branch 1 taken 355 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 55 times.
✓ Branch 4 taken 300 times.
355 if (breadcrumb.IsValid()) {
158 55 local_newest_hash = breadcrumb.catalog_hash;
159 55 local_newest_timestamp = breadcrumb.timestamp;
160 55 local_newest_revision = breadcrumb.revision;
161
1/2
✓ Branch 3 taken 55 times.
✗ Branch 4 not taken.
110 LogCvmfs(kLogCache, kLogDebug,
162 "Cached copy publish date %s (hash %s, revision %" PRIu64 ")",
163
1/2
✓ Branch 1 taken 55 times.
✗ Branch 2 not taken.
110 StringifyTime(static_cast<int64_t>(local_newest_timestamp), true)
164 .c_str(),
165
1/2
✓ Branch 1 taken 55 times.
✗ Branch 2 not taken.
110 local_newest_hash.ToString().c_str(), breadcrumb.revision);
166 } else {
167
1/2
✓ Branch 2 taken 300 times.
✗ Branch 3 not taken.
300 LogCvmfs(kLogCache, kLogDebug, "Unable to read local checksum %s",
168
1/2
✓ Branch 1 taken 300 times.
✗ Branch 2 not taken.
600 breadcrumb.ToString().c_str());
169 }
170
171 // 2) Select local newest catalog: mounted vs alien
172
173 355 result->SetRootCtlgLocation(kCtlgLocationBreadcrumb);
174 355 LoadReturn success_code = catalog::kLoadNew;
175
176
2/2
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 331 times.
355 if (mounted_catalogs_.size() > 0) {
177 const std::map<PathString, shash::Any>::iterator
178
2/4
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
24 curr_hash_itr = mounted_catalogs_.find(PathString("", 0));
179 24 mounted_hash = curr_hash_itr->second;
180 }
181
182 // We only look for currently loaded catalog if the revision is newer than
183 // the breadcrumb revision and both revision numbers are valid (!= -1ul).
184 355 if ((local_newest_revision <= GetRevisionNoLock()
185
1/2
✓ Branch 0 taken 300 times.
✗ Branch 1 not taken.
300 || local_newest_revision == manifest::Breadcrumb::kInvalidRevision)
186
6/6
✓ Branch 0 taken 300 times.
✓ Branch 1 taken 55 times.
✓ Branch 3 taken 24 times.
✓ Branch 4 taken 331 times.
✓ Branch 5 taken 24 times.
✓ Branch 6 taken 331 times.
655 && mounted_catalogs_.size() > 0) {
187 24 local_newest_hash = mounted_hash;
188 24 local_newest_revision = GetRevisionNoLock();
189 // if needed for integration test 707: breadcrumb_timestamp_newer()
190 24 local_newest_timestamp = GetTimestampNoLock() > local_newest_timestamp
191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 ? GetTimestampNoLock()
192 : local_newest_timestamp;
193 24 result->SetRootCtlgLocation(kCtlgLocationMounted);
194 24 success_code = catalog::kLoadUp2Date;
195
4/6
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 300 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 31 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 331 times.
331 } else if (local_newest_revision == 0 && mounted_catalogs_.size() > 0) {
196 // breadcrumb has no revision
197 // TODO(heretherebedragons) this branch can be removed in future versions
198
199 // revisions are better, but if we dont have any we need to compare by
200 // timestamp (you can have multiple revisions in the same timestamp)
201 if (local_newest_timestamp < GetTimestampNoLock()) {
202 local_newest_hash = mounted_hash;
203 local_newest_revision = GetRevisionNoLock();
204 local_newest_timestamp = GetTimestampNoLock();
205 result->SetRootCtlgLocation(kCtlgLocationMounted);
206 success_code = catalog::kLoadUp2Date;
207 }
208 }
209
210 // 3) Get remote root catalog (fails if remote catalog is older)
211 manifest::Failures manifest_failure;
212 UniquePtr<CachedManifestEnsemble> ensemble(
213
2/4
✓ Branch 2 taken 355 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 355 times.
✗ Branch 7 not taken.
355 new CachedManifestEnsemble(fetcher_->cache_mgr(), this));
214
2/4
✓ Branch 1 taken 355 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 355 times.
✗ Branch 5 not taken.
355 manifest_failure = manifest::Fetch(
215 355 "", repo_name_, local_newest_timestamp, &local_newest_hash,
216 355 signature_mgr_, fetcher_->download_mgr(), ensemble.weak_ref());
217
218
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 155 times.
355 if (manifest_failure == manifest::kFailOk) {
219 // server has newest revision or no valid local revision
220 200 if (ensemble->manifest->revision() > local_newest_revision
221
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 155 times.
198 || local_newest_revision == manifest::Breadcrumb::kInvalidRevision
222 // if revision is 0 both local and server, load catalog from server
223 // as local is most likely just "initialized" without valid value
224
6/6
✓ Branch 0 taken 198 times.
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 33 times.
✓ Branch 5 taken 10 times.
✓ Branch 6 taken 190 times.
✓ Branch 7 taken 10 times.
431 || (ensemble->manifest->revision() == 0
225
1/2
✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
33 && local_newest_revision == 0)) {
226 190 result->SetHash(ensemble->manifest->catalog_hash());
227 190 result->SetRootCtlgRevision(ensemble->manifest->revision());
228 190 result->SetRootCtlgLocation(kCtlgLocationServer);
229 190 fixed_alt_root_catalog_ = ensemble->manifest->has_alt_catalog_path();
230
231
1/2
✓ Branch 1 taken 190 times.
✗ Branch 2 not taken.
190 result->TakeManifestEnsemble(
232 190 static_cast<manifest::ManifestEnsemble *>(ensemble.Release()));
233 190 offline_mode_ = false;
234
235 190 return catalog::kLoadNew;
236 }
237 }
238
1/2
✓ Branch 2 taken 165 times.
✗ Branch 3 not taken.
165 LogCvmfs(kLogCache, kLogDebug,
239 "Failed fetch manifest from server: "
240 "manifest too old or server unreachable (%d - %s)",
241 manifest_failure, manifest::Code2Ascii(manifest_failure));
242
243 // total failure: server not reachable and no valid local hash
244
6/6
✓ Branch 0 taken 155 times.
✓ Branch 1 taken 10 times.
✓ Branch 3 taken 145 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 145 times.
✓ Branch 6 taken 20 times.
165 if ((manifest_failure != manifest::kFailOk) && local_newest_hash.IsNull()) {
245
1/2
✓ Branch 1 taken 145 times.
✗ Branch 2 not taken.
145 LogCvmfs(kLogCache, kLogDebug, "No valid root catalog found!");
246 145 return catalog::kLoadFail;
247 }
248
249 20 if (manifest_failure == manifest::kFailOk
250
5/6
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10 times.
✓ Branch 7 taken 10 times.
20 && ensemble->manifest->revision() == local_newest_revision) {
251 10 offline_mode_ = false;
252 } else {
253 10 offline_mode_ = true;
254 }
255 20 result->SetHash(local_newest_hash);
256 20 result->SetRootCtlgRevision(local_newest_revision);
257
258 // for integration test 707: breadcrumb_revision_large()
259
4/8
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 20 times.
✗ Branch 9 not taken.
20 if (breadcrumb.IsValid() && breadcrumb.catalog_hash == mounted_hash) {
260 20 success_code = catalog::kLoadUp2Date;
261 }
262
263 20 return success_code;
264 355 }
265
266 854 std::string ClientCatalogManager::GetCatalogDescription(
267 const PathString &mountpoint, const shash::Any &hash) {
268
2/4
✓ Branch 1 taken 854 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 854 times.
✗ Branch 5 not taken.
1708 return "file catalog at " + repo_name_ + ":"
269
2/4
✓ Branch 1 taken 854 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 854 times.
✗ Branch 5 not taken.
2562 + (mountpoint.IsEmpty()
270
8/14
✓ Branch 0 taken 641 times.
✓ Branch 1 taken 213 times.
✓ Branch 4 taken 641 times.
✗ Branch 5 not taken.
✓ Branch 9 taken 213 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 213 times.
✓ Branch 13 taken 641 times.
✓ Branch 15 taken 641 times.
✓ Branch 16 taken 213 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1921 ? "/"
271 213 : string(mountpoint.GetChars(), mountpoint.GetLength()))
272
3/6
✓ Branch 2 taken 854 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 854 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 854 times.
✗ Branch 9 not taken.
3416 + " (" + hash.ToString() + ")";
273 }
274
275 /**
276 * Loads (and fetches) a catalog by hash for a given mountpoint.
277 *
278 * Special case for root catalog: ctlg_context->root_ctlg_location must be
279 * given.
280 *
281 * @param [in, out] ctlg_context mandatory fields (input): mountpoint, hash
282 * additional mandatory fields for root catalog: root_ctlg_location
283 * output: sqlite_path is set if catalog fetch successful
284 * @return kLoadUp2Date for root catalog that is already mounted
285 * kLoadNew for any other successful load
286 * kLoadFail on failure
287 */
288 803 LoadReturn ClientCatalogManager::LoadCatalogByHash(
289 CatalogContext *ctlg_context) {
290
1/2
✓ Branch 1 taken 803 times.
✗ Branch 2 not taken.
803 const string catalog_descr = GetCatalogDescription(ctlg_context->mountpoint(),
291
1/2
✓ Branch 2 taken 803 times.
✗ Branch 3 not taken.
1606 ctlg_context->hash());
292
1/2
✓ Branch 2 taken 803 times.
✗ Branch 3 not taken.
803 string alt_root_catalog_path = "";
293
294 // root catalog needs special handling because of alt_root_catalog_path
295
5/8
✓ Branch 1 taken 803 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 641 times.
✓ Branch 4 taken 162 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 641 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 803 times.
803 if (ctlg_context->IsRootCatalog() && fixed_alt_root_catalog_) {
296 alt_root_catalog_path = ctlg_context->hash().MakeAlternativePath();
297 }
298
299
1/2
✓ Branch 2 taken 803 times.
✗ Branch 3 not taken.
1606 const LoadReturn load_ret = FetchCatalogByHash(
300 803 ctlg_context->hash(), catalog_descr, alt_root_catalog_path,
301 ctlg_context->GetSqlitePathPtr());
302
2/2
✓ Branch 0 taken 793 times.
✓ Branch 1 taken 10 times.
803 if (load_ret == catalog::kLoadNew) {
303
2/4
✓ Branch 2 taken 793 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 793 times.
✗ Branch 6 not taken.
793 loaded_catalogs_[ctlg_context->mountpoint()] = ctlg_context->hash();
304
305
3/4
✓ Branch 1 taken 793 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 641 times.
✓ Branch 4 taken 152 times.
793 if (ctlg_context->IsRootCatalog()) {
306
2/2
✓ Branch 1 taken 453 times.
✓ Branch 2 taken 188 times.
641 if (ctlg_context->root_ctlg_location() == kCtlgLocationMounted) {
307 453 return kLoadUp2Date;
308 }
309
310 // if coming from server: update breadcrumb
311
1/2
✓ Branch 1 taken 188 times.
✗ Branch 2 not taken.
188 if (ctlg_context->root_ctlg_location() == kCtlgLocationServer) {
312 // Store new manifest and certificate
313 188 CacheManager::Label label;
314
1/2
✓ Branch 1 taken 188 times.
✗ Branch 2 not taken.
188 label.path = repo_name_;
315 188 label.flags |= CacheManager::kLabelCertificate;
316
3/4
✓ Branch 1 taken 188 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 156 times.
✓ Branch 4 taken 32 times.
188 if (ctlg_context->manifest_ensemble()->cert_size > 0) {
317
1/2
✓ Branch 2 taken 156 times.
✗ Branch 3 not taken.
312 fetcher_->cache_mgr()->CommitFromMem(
318
1/2
✓ Branch 1 taken 156 times.
✗ Branch 2 not taken.
312 CacheManager::LabeledObject(
319 312 ctlg_context->manifest_ensemble()->manifest->certificate(),
320 label),
321
1/2
✓ Branch 1 taken 156 times.
✗ Branch 2 not taken.
156 ctlg_context->manifest_ensemble()->cert_buf,
322
2/4
✓ Branch 1 taken 156 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 156 times.
✗ Branch 5 not taken.
156 ctlg_context->manifest_ensemble()->cert_size);
323 }
324 188 fetcher_->cache_mgr()->StoreBreadcrumb(
325
2/4
✓ Branch 1 taken 188 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 188 times.
✗ Branch 5 not taken.
188 *ctlg_context->manifest_ensemble()->manifest);
326 188 }
327 }
328 }
329
330 350 return load_ret;
331 803 }
332
333 /**
334 * Fetch a catalog by hash either from cache or from remote.
335 * Successful load always returns kLoadNew (independent of the location) and
336 * sets the sqlite_path variable.
337 *
338 * @param [out] sqlite_path of the catalog if successfully fetched
339 * @return kLoadNew on success
340 * kLoadNoSpace out of space, no room on the device to open the catalog
341 * kLoadFail on all other failures
342 */
343 803 LoadReturn ClientCatalogManager::FetchCatalogByHash(
344 const shash::Any &hash,
345 const string &name,
346 const std::string &alt_root_catalog_path,
347 std::string *sqlite_path) {
348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 803 times.
803 assert(hash.suffix == shash::kSuffixCatalog);
349 803 CacheManager::Label label;
350
1/2
✓ Branch 1 taken 803 times.
✗ Branch 2 not taken.
803 label.path = name;
351 803 label.flags = CacheManager::kLabelCatalog;
352
2/4
✓ Branch 1 taken 803 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 803 times.
✗ Branch 5 not taken.
803 const int fd = fetcher_->Fetch(CacheManager::LabeledObject(hash, label),
353 alt_root_catalog_path);
354
2/2
✓ Branch 0 taken 793 times.
✓ Branch 1 taken 10 times.
803 if (fd >= 0) {
355
2/2
✓ Branch 0 taken 619 times.
✓ Branch 1 taken 174 times.
793 if (root_fd_ < 0) {
356 619 root_fd_ = fd;
357 }
358
359
1/2
✓ Branch 1 taken 793 times.
✗ Branch 2 not taken.
793 LogCvmfs(kLogCatalog, kLogDebug, "FetchCatalogByHash filedescriptor %d",
360 fd);
361
2/4
✓ Branch 1 taken 793 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 793 times.
✗ Branch 5 not taken.
793 *sqlite_path = "@" + StringifyInt(fd);
362 793 return kLoadNew;
363 }
364
365
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (fd == -ENOSPC)
366 return kLoadNoSpace;
367
368 10 return kLoadFail;
369 803 }
370
371 51 void ClientCatalogManager::StageNestedCatalogByHash(
372 const shash::Any &hash, const PathString &mountpoint) {
373
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 assert(hash.suffix == shash::kSuffixCatalog);
374
375 51 CacheManager::Label label;
376
1/2
✓ Branch 1 taken 51 times.
✗ Branch 2 not taken.
51 label.path = GetCatalogDescription(mountpoint, hash);
377 51 label.flags = CacheManager::kLabelCatalog;
378
3/6
✓ Branch 2 taken 51 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 51 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 51 times.
✗ Branch 9 not taken.
51 const int fd = fetcher_->Fetch(CacheManager::LabeledObject(hash, label));
379
1/2
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
51 if (fd >= 0)
380
1/2
✓ Branch 2 taken 51 times.
✗ Branch 3 not taken.
51 fetcher_->cache_mgr()->Close(fd);
381 51 }
382
383 2 void ClientCatalogManager::UnloadCatalog(const Catalog *catalog) {
384
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 LogCvmfs(kLogCache, kLogDebug, "unloading catalog %s",
385
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 catalog->mountpoint().c_str());
386
387
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 const map<PathString, shash::Any>::iterator iter = mounted_catalogs_.find(
388
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 catalog->mountpoint());
389
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 assert(iter != mounted_catalogs_.end());
390
1/2
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 fetcher_->cache_mgr()->quota_mgr()->Unpin(iter->second);
391
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 mounted_catalogs_.erase(iter);
392 2 const catalog::Counters &counters = catalog->GetCounters();
393
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 loaded_inodes_ -= counters.GetSelfEntries();
394 2 }
395
396
397 /**
398 * Checks if the current repository revision is blacklisted. The format
399 * of the blacklist lines is '<REPO N' where REPO is the repository name,
400 * N is the revision number, and the two parts are separated by whitespace.
401 * Any revision of REPO less than N is blacklisted.
402 * Note: no extra characters are allowed after N, not even whitespace.
403 * @return true if it is blacklisted, false otherwise
404 */
405 619 bool ClientCatalogManager::IsRevisionBlacklisted() {
406 619 const uint64_t revision = GetRevision();
407
408
1/2
✓ Branch 2 taken 619 times.
✗ Branch 3 not taken.
619 LogCvmfs(kLogCache, kLogDebug,
409 "checking if %s revision %" PRIu64 " is blacklisted",
410 repo_name_.c_str(), revision);
411
412
1/2
✓ Branch 1 taken 619 times.
✗ Branch 2 not taken.
619 vector<string> blacklist = signature_mgr_->GetBlacklist();
413
2/2
✓ Branch 1 taken 31 times.
✓ Branch 2 taken 588 times.
619 for (unsigned i = 0; i < blacklist.size(); ++i) {
414
1/2
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
31 std::string line = blacklist[i];
415
2/4
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 31 times.
31 if (line[0] != '<')
416 continue;
417 31 unsigned idx = repo_name_.length() + 1;
418
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
31 if (line.length() <= idx)
419 continue;
420
3/10
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 31 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 31 times.
31 if ((line[idx] != ' ') && (line[idx] != '\t'))
421 continue;
422
2/4
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 31 times.
31 if (line.substr(1, idx - 1) != repo_name_)
423 continue;
424 31 ++idx;
425
5/10
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 31 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 31 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 31 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 31 times.
31 while ((line[idx] == ' ') || (line[idx] == '\t'))
426 ++idx;
427
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
31 if (idx >= line.length())
428 continue;
429 uint64_t rev;
430
3/6
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 31 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 31 times.
31 if (!String2Uint64Parse(line.substr(idx), &rev))
431 continue;
432
1/2
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
31 if (revision < rev)
433 31 return true;
434
1/3
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31 times.
31 }
435
436 588 return false;
437 619 }
438
439
440 //------------------------------------------------------------------------------
441
442
443 219 void CachedManifestEnsemble::FetchCertificate(const shash::Any &hash) {
444 219 CacheManager::Label label;
445 219 label.flags |= CacheManager::kLabelCertificate;
446
1/2
✓ Branch 1 taken 219 times.
✗ Branch 2 not taken.
219 label.path = catalog_mgr_->repo_name();
447 uint64_t size;
448
1/2
✓ Branch 1 taken 219 times.
✗ Branch 2 not taken.
219 const bool retval = cache_mgr_->Open2Mem(
449
1/2
✓ Branch 1 taken 219 times.
✗ Branch 2 not taken.
438 CacheManager::LabeledObject(hash, label), &cert_buf, &size);
450 219 cert_size = size;
451
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 217 times.
219 if (retval)
452 2 perf::Inc(catalog_mgr_->n_certificate_hits_);
453 else
454 217 perf::Inc(catalog_mgr_->n_certificate_misses_);
455 219 }
456
457 } // namespace catalog
458