CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
manifest.h
Go to the documentation of this file.
1 
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 
22 struct Breadcrumb {
23  static const uint64_t kInvalidRevision = -1ul;
24 
26  Breadcrumb(const shash::Any &h, uint64_t t, uint64_t r) :
27  catalog_hash(h),
28  timestamp(t),
29  revision(r) {}
30  explicit Breadcrumb(const std::string &from_string);
31 
32  bool Export(const std::string &fqrn,
33  const std::string &directory, const int mode) const;
34  std::string ToString() const;
35  bool IsValid() const { return !catalog_hash.IsNull()
36  && (timestamp > 0)
37  && (revision != kInvalidRevision); }
38 
40  uint64_t timestamp;
41  uint64_t revision;
42 };
43 
44 
49 class Manifest {
50  public:
51  static Manifest *LoadFile(const std::string &path);
52  static Manifest *LoadMem(const unsigned char *buffer, const unsigned length);
54  const uint64_t catalog_size,
55  const std::string &root_path);
56  Manifest(const shash::Any &catalog_hash,
57  const uint64_t catalog_size,
58  const shash::Md5 &root_path,
59  const uint32_t ttl,
60  const uint64_t revision,
61  const shash::Any &micro_catalog_hash,
62  const std::string &repository_name,
63  const shash::Any certificate,
64  const shash::Any history,
65  const uint64_t publish_timestamp,
66  const bool garbage_collectable,
67  const bool has_alt_catalog_path,
68  const shash::Any &meta_info,
69  const shash::Any &reflog_hash)
70  : catalog_hash_(catalog_hash)
71  , catalog_size_(catalog_size)
72  , root_path_(root_path)
73  , ttl_(ttl)
74  , revision_(revision)
75  , micro_catalog_hash_(micro_catalog_hash)
76  , repository_name_(repository_name)
77  , certificate_(certificate)
78  , history_(history)
79  , publish_timestamp_(publish_timestamp)
80  , garbage_collectable_(garbage_collectable)
81  , has_alt_catalog_path_(has_alt_catalog_path)
82  , meta_info_(meta_info)
83  , reflog_hash_(reflog_hash) {}
84 
85  std::string ExportString() const;
86  bool Export(const std::string &path) const;
87  bool ExportBreadcrumb(const std::string &directory, const int mode) const;
88  static Breadcrumb ReadBreadcrumb(const std::string &repo_name,
89  const std::string &directory);
90 
92 
93  void set_ttl(const uint32_t ttl) { ttl_ = ttl; }
94  void set_revision(const uint64_t revision) { revision_ = revision; }
97  }
98  void set_history(const shash::Any &history_db) {
99  history_ = history_db;
100  }
101  void set_repository_name(const std::string &repository_name) {
103  }
106  }
107  void set_catalog_size(const uint64_t catalog_size) {
109  }
110  void set_catalog_hash(const shash::Any &catalog_hash) {
112  }
115  }
116  void set_has_alt_catalog_path(const bool &has_alt_path) {
117  has_alt_catalog_path_ = has_alt_path;
118  }
121  }
122  void set_root_path(const std::string &root_path) {
123  root_path_ = shash::Md5(shash::AsciiPtr(root_path));
124  }
125  void set_reflog_hash(const shash::Any& checksum) {
126  reflog_hash_ = checksum;
127  }
128 
129  uint64_t revision() const { return revision_; }
130  std::string repository_name() const { return repository_name_; }
131  shash::Md5 root_path() const { return root_path_; }
133  uint64_t catalog_size() const { return catalog_size_; }
134  shash::Any certificate() const { return certificate_; }
135  shash::Any history() const { return history_; }
136  uint64_t publish_timestamp() const { return publish_timestamp_; }
137  bool garbage_collectable() const { return garbage_collectable_; }
139  shash::Any meta_info() const { return meta_info_; }
140  shash::Any reflog_hash() const { return reflog_hash_; }
141 
142  std::string MakeCatalogPath() const {
144  ("data/" + catalog_hash_.MakePath());
145  }
146 
147  std::string MakeCertificatePath() const {
148  return has_alt_catalog_path_ ?
150  }
151 
152  private:
153  static Manifest *Load(const std::map<char, std::string> &content);
155  uint64_t catalog_size_;
157  uint32_t ttl_;
158  uint64_t revision_;
160  std::string repository_name_;
165 
172 
178 
183 }; // class Manifest
184 
185 } // namespace manifest
186 
187 #endif // CVMFS_MANIFEST_H_
void set_repository_name(const std::string &repository_name)
Definition: manifest.h:101
bool IsNull() const
Definition: hash.h:383
shash::Any micro_catalog_hash_
Definition: manifest.h:159
const manifest::Manifest * manifest() const
Definition: repository.h:125
bool Export(const std::string &path) const
Definition: manifest.cc:223
static Manifest * LoadMem(const unsigned char *buffer, const unsigned length)
Definition: manifest.cc:82
uint64_t timestamp
Definition: manifest.h:40
void set_catalog_hash(const shash::Any &catalog_hash)
Definition: manifest.h:110
std::string MakeAlternativePath() const
Definition: hash.h:325
shash::Any meta_info_
Definition: manifest.h:177
shash::Any catalog_hash
Definition: manifest.h:39
shash::Any certificate_
Definition: manifest.h:161
shash::Md5 root_path_
Definition: manifest.h:156
Manifest(const shash::Any &catalog_hash, const uint64_t catalog_size, const std::string &root_path)
void set_certificate(const shash::Any &certificate)
Definition: manifest.h:95
bool garbage_collectable_
Definition: manifest.h:164
static const uint64_t kInvalidRevision
Definition: manifest.h:23
void set_meta_info(const shash::Any &meta_info)
Definition: manifest.h:119
std::string ExportString() const
Definition: manifest.cc:188
void set_revision(const uint64_t revision)
Definition: manifest.h:94
shash::Any reflog_hash_
Definition: manifest.h:182
std::string MakeCertificatePath() const
Definition: manifest.h:147
bool has_alt_catalog_path() const
Definition: manifest.h:138
Algorithms algorithm
Definition: hash.h:125
uint64_t catalog_size() const
Definition: manifest.h:133
uint64_t revision() const
Definition: manifest.h:129
Algorithms
Definition: hash.h:41
uint64_t revision_
Definition: manifest.h:158
uint64_t revision
Definition: manifest.h:41
bool ExportBreadcrumb(const std::string &directory, const int mode) const
Definition: manifest.cc:246
uint64_t publish_timestamp() const
Definition: manifest.h:136
std::string repository_name() const
Definition: manifest.h:130
void set_publish_timestamp(const uint32_t publish_timestamp)
Definition: manifest.h:104
shash::Any certificate() const
Definition: manifest.h:134
shash::Any catalog_hash() const
Definition: manifest.h:132
bool garbage_collectable() const
Definition: manifest.h:137
bool has_alt_catalog_path_
Definition: manifest.h:171
bool Export(const std::string &fqrn, const std::string &directory, const int mode) const
Definition: manifest.cc:48
std::string repository_name_
Definition: manifest.h:160
void set_history(const shash::Any &history_db)
Definition: manifest.h:98
void set_garbage_collectability(const bool garbage_collectable)
Definition: manifest.h:113
void set_ttl(const uint32_t ttl)
Definition: manifest.h:93
shash::Algorithms GetHashAlgorithm() const
Definition: manifest.h:91
std::string ToString() const
Definition: manifest.cc:72
shash::Any history() const
Definition: manifest.h:135
void set_catalog_size(const uint64_t catalog_size)
Definition: manifest.h:107
shash::Md5 root_path() const
Definition: manifest.h:131
bool IsValid() const
Definition: manifest.h:35
std::string MakeCatalogPath() const
Definition: manifest.h:142
Manifest(const shash::Any &catalog_hash, const uint64_t catalog_size, const shash::Md5 &root_path, const uint32_t ttl, const uint64_t revision, const shash::Any &micro_catalog_hash, const std::string &repository_name, const shash::Any certificate, const shash::Any history, const uint64_t publish_timestamp, const bool garbage_collectable, const bool has_alt_catalog_path, const shash::Any &meta_info, const shash::Any &reflog_hash)
Definition: manifest.h:56
static Breadcrumb ReadBreadcrumb(const std::string &repo_name, const std::string &directory)
Definition: manifest.cc:256
void set_has_alt_catalog_path(const bool &has_alt_path)
Definition: manifest.h:116
shash::Any catalog_hash_
Definition: manifest.h:154
shash::Any reflog_hash() const
Definition: manifest.h:140
shash::Any history_
Definition: manifest.h:162
std::string MakePath() const
Definition: hash.h:316
uint64_t publish_timestamp_
Definition: manifest.h:163
void set_reflog_hash(const shash::Any &checksum)
Definition: manifest.h:125
uint64_t catalog_size_
Definition: manifest.h:155
static Manifest * LoadFile(const std::string &path)
Definition: manifest.cc:92
Breadcrumb(const shash::Any &h, uint64_t t, uint64_t r)
Definition: manifest.h:26
static Manifest * Load(const std::map< char, std::string > &content)
Definition: manifest.cc:101
shash::Any meta_info() const
Definition: manifest.h:139
void set_root_path(const std::string &root_path)
Definition: manifest.h:122