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