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