GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/upload.cc
Date: 2024-04-21 02:33:16
Exec Total Coverage
Lines: 42 78 53.8%
Branches: 14 46 30.4%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5 #include "upload.h"
6 #include "cvmfs_config.h"
7
8 #include <vector>
9
10 #include "util/concurrency.h"
11 #include "util/shared_ptr.h"
12
13 namespace upload {
14
15 24 Spooler *Spooler::Construct(const SpoolerDefinition &spooler_definition,
16 perf::StatisticsTemplate *statistics) {
17
1/2
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 Spooler *result = new Spooler(spooler_definition);
18
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
24 if (!result->Initialize(statistics)) {
19 delete result;
20 result = NULL;
21 }
22 24 return result;
23 }
24
25 24 Spooler::Spooler(const SpoolerDefinition &spooler_definition)
26
3/6
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 24 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 24 times.
✗ Branch 9 not taken.
24 : spooler_definition_(spooler_definition) {}
27
28 144 Spooler::~Spooler() {
29 48 FinalizeSession(false);
30
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
48 if (uploader_.IsValid()) {
31 48 uploader_->TearDown();
32 }
33 96 }
34
35 std::string Spooler::backend_name() const { return uploader_->name(); }
36
37 24 bool Spooler::Initialize(perf::StatisticsTemplate *statistics) {
38 // configure the uploader environment
39 24 uploader_ = AbstractUploader::Construct(spooler_definition_);
40
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
24 if (!uploader_.IsValid()) {
41 LogCvmfs(kLogSpooler, kLogWarning,
42 "Failed to initialize backend upload "
43 "facility in Spooler.");
44 return false;
45 }
46
47
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 22 times.
24 if (statistics != NULL) {
48 2 uploader_->InitCounters(statistics);
49 }
50
51 // configure the file processor context
52 ingestion_pipeline_ =
53
1/2
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
24 new IngestionPipeline(uploader_.weak_ref(), spooler_definition_);
54 24 ingestion_pipeline_->RegisterListener(&Spooler::ProcessingCallback, this);
55 24 ingestion_pipeline_->Spawn();
56
57 // all done...
58 24 return true;
59 }
60
61 bool Spooler::Create() {
62 return uploader_->Create();
63 }
64
65 void Spooler::Process(IngestionSource *source, const bool allow_chunking) {
66 ingestion_pipeline_->Process(source, allow_chunking);
67 }
68
69 46 void Spooler::ProcessCatalog(const std::string &local_path) {
70
1/2
✓ Branch 3 taken 46 times.
✗ Branch 4 not taken.
46 ingestion_pipeline_->Process(new FileIngestionSource(local_path), false,
71 shash::kSuffixCatalog);
72 46 }
73
74 void Spooler::ProcessHistory(const std::string &local_path) {
75 ingestion_pipeline_->Process(new FileIngestionSource(local_path), false,
76 shash::kSuffixHistory);
77 }
78
79 void Spooler::ProcessCertificate(const std::string &local_path) {
80 ingestion_pipeline_->Process(new FileIngestionSource(local_path), false,
81 shash::kSuffixCertificate);
82 }
83
84 void Spooler::ProcessCertificate(IngestionSource *source) {
85 ingestion_pipeline_->Process(source, false, shash::kSuffixCertificate);
86 }
87
88 void Spooler::ProcessMetainfo(const std::string &local_path) {
89 ingestion_pipeline_->Process(new FileIngestionSource(local_path), false,
90 shash::kSuffixMetainfo);
91 }
92
93 void Spooler::ProcessMetainfo(IngestionSource *source) {
94 ingestion_pipeline_->Process(source, false, shash::kSuffixMetainfo);
95 }
96
97 22 void Spooler::Upload(const std::string &local_path,
98 const std::string &remote_path) {
99 22 uploader_->UploadFile(
100 local_path, remote_path,
101 22 AbstractUploader::MakeCallback(&Spooler::UploadingCallback, this));
102 22 }
103
104 void Spooler::Upload(const std::string &remote_path, IngestionSource *source) {
105 uploader_->UploadIngestionSource(
106 remote_path, source,
107 AbstractUploader::MakeCallback(&Spooler::UploadingCallback, this));
108 delete source;
109 }
110
111
112 void Spooler::UploadManifest(const std::string &local_path) {
113 Upload(local_path, ".cvmfspublished");
114 }
115
116 void Spooler::UploadReflog(const std::string &local_path) {
117 Upload(local_path, ".cvmfsreflog");
118 }
119
120 void Spooler::RemoveAsync(const std::string &file_to_delete) {
121 uploader_->RemoveAsync(file_to_delete);
122 }
123
124 bool Spooler::Peek(const std::string &path) const {
125 return uploader_->Peek(path);
126 }
127
128 bool Spooler::Mkdir(const std::string &path) {
129 return uploader_->Mkdir(path);
130 }
131
132 bool Spooler::PlaceBootstrappingShortcut(const shash::Any &object) const {
133 assert(!object.IsNull());
134 return uploader_->PlaceBootstrappingShortcut(object);
135 }
136
137 46 void Spooler::ProcessingCallback(const SpoolerResult &data) {
138 46 NotifyListeners(data);
139 46 }
140
141 22 void Spooler::UploadingCallback(const UploaderResults &data) {
142
3/6
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 22 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 22 times.
✗ Branch 9 not taken.
22 NotifyListeners(SpoolerResult(data.return_code, data.local_path));
143 22 }
144
145 42 void Spooler::WaitForUpload() const {
146 42 ingestion_pipeline_->WaitFor();
147 42 uploader_->WaitForUpload();
148 42 }
149
150 24 bool Spooler::FinalizeSession(bool commit, const std::string &old_root_hash,
151 const std::string &new_root_hash,
152 const RepositoryTag &tag) const {
153 24 return uploader_->FinalizeSession(commit, old_root_hash,
154 24 new_root_hash, tag);
155 }
156
157 64 unsigned int Spooler::GetNumberOfErrors() const {
158 64 return uploader_->GetNumberOfErrors();
159 }
160
161 } // namespace upload
162