GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/swissknife_assistant.cc
Date: 2026-10-04 02:40:33
Exec Total Coverage
Lines: 0 59 0.0%
Branches: 0 87 0.0%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System
3 */
4
5 #include "swissknife_assistant.h"
6
7 #include <unistd.h>
8
9 #include <cassert>
10 #include <cstdlib>
11
12 #include "catalog.h"
13 #include "catalog_rw.h"
14 #include "history.h"
15 #include "history_sqlite.h"
16 #include "manifest.h"
17 #include "network/download.h"
18 #include "network/sink_path.h"
19 #include "util/logging.h"
20 #include "util/posix.h"
21
22 using namespace std; // NOLINT
23
24 namespace swissknife {
25
26 ✗ catalog::Catalog *Assistant::GetCatalog(const shash::Any &catalog_hash,
27 OpenMode open_mode) {
28 ✗ assert(shash::kSuffixCatalog == catalog_hash.suffix);
29 ✗ const string local_path = CreateTempPath(tmp_dir_ + "/catalog", 0600);
30 ✗ assert(!local_path.empty());
31
32 ✗ if (!FetchObject(catalog_hash, local_path)) {
33 ✗ return NULL;
34 }
35
36 ✗ const std::string catalog_root_path = "";
37 catalog::Catalog *catalog;
38 ✗ switch (open_mode) {
39 ✗ case kOpenReadWrite:
40 ✗ catalog = catalog::WritableCatalog::AttachFreely(
41 catalog_root_path, local_path, catalog_hash);
42 ✗ break;
43 ✗ case kOpenReadOnly:
44 ✗ catalog = catalog::Catalog::AttachFreely(catalog_root_path, local_path,
45 catalog_hash);
46 ✗ break;
47 ✗ default:
48 ✗ abort();
49 }
50 ✗ assert(catalog != NULL);
51 ✗ catalog->TakeDatabaseFileOwnership();
52 ✗ return catalog;
53 }
54
55
56 ✗ history::History *Assistant::GetHistory(OpenMode open_mode) {
57 ✗ const shash::Any history_hash = manifest_->history();
58 history::History *history;
59
60 ✗ const string local_path = CreateTempPath(tmp_dir_ + "/history", 0600);
61 ✗ assert(!local_path.empty());
62
63 ✗ if (history_hash.IsNull()) {
64 ✗ history = history::SqliteHistory::Create(local_path,
65 ✗ manifest_->repository_name());
66 ✗ if (NULL == history) {
67 ✗ LogCvmfs(kLogCvmfs, kLogStderr, "failed to create history database");
68 ✗ return NULL;
69 }
70 ✗ return history;
71 }
72
73 ✗ if (!FetchObject(history_hash, local_path))
74 ✗ return NULL;
75
76 ✗ switch (open_mode) {
77 ✗ case kOpenReadWrite:
78 ✗ history = history::SqliteHistory::OpenWritable(local_path);
79 ✗ break;
80 ✗ case kOpenReadOnly:
81 ✗ history = history::SqliteHistory::Open(local_path);
82 ✗ break;
83 ✗ default:
84 ✗ abort();
85 }
86
87 ✗ if (history == NULL) {
88 ✗ LogCvmfs(kLogCvmfs, kLogStderr, "failed to open history database (%s)",
89 local_path.c_str());
90 ✗ unlink(local_path.c_str());
91 ✗ return NULL;
92 }
93 ✗ assert(history->fqrn() == manifest_->repository_name());
94 ✗ history->TakeDatabaseFileOwnership();
95 ✗ return history;
96 }
97
98
99 ✗ bool Assistant::FetchObject(const shash::Any &id, const string &local_path) {
100 ✗ assert(!id.IsNull());
101
102 download::Failures dl_retval;
103 ✗ const std::string url = repository_url_ + "/data/" + id.MakePath();
104
105 ✗ cvmfs::PathSink pathsink(local_path);
106 ✗ download::JobInfo download_info(&url, true, false, &id, &pathsink);
107 ✗ dl_retval = download_mgr_->Fetch(&download_info);
108
109 ✗ if (dl_retval != download::kFailOk) {
110 ✗ LogCvmfs(kLogCvmfs, kLogStderr, "failed to download object '%s' (%d - %s)",
111 ✗ id.ToStringWithSuffix().c_str(), dl_retval,
112 download::Code2Ascii(dl_retval));
113 ✗ return false;
114 }
115 ✗ return true;
116 }
117
118 } // namespace swissknife
119