CernVM-FS  2.13.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), 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  bool IsValid() const {
34  return !catalog_hash.IsNull() && (timestamp > 0)
35  && (revision != kInvalidRevision);
36  }
37 
39  uint64_t timestamp;
40  uint64_t revision;
41 };
42 
43 
48 class Manifest {
49  public:
50  static Manifest *LoadFile(const std::string &path);
51  static Manifest *LoadMem(const unsigned char *buffer, const unsigned length);
53  const uint64_t catalog_size,
54  const std::string &root_path);
55  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 &micro_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  : catalog_hash_(catalog_hash)
70  , catalog_size_(catalog_size)
71  , root_path_(root_path)
72  , ttl_(ttl)
73  , revision_(revision)
74  , micro_catalog_hash_(micro_catalog_hash)
75  , repository_name_(repository_name)
76  , certificate_(certificate)
77  , history_(history)
78  , publish_timestamp_(publish_timestamp)
79  , garbage_collectable_(garbage_collectable)
80  , has_alt_catalog_path_(has_alt_catalog_path)
81  , meta_info_(meta_info)
82  , 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 
91 
92  void set_ttl(const uint32_t ttl) { ttl_ = ttl; }
93  void set_revision(const uint64_t revision) { revision_ = revision; }
96  }
97  void set_history(const shash::Any &history_db) { history_ = history_db; }
98  void set_repository_name(const std::string &repository_name) {
100  }
103  }
104  void set_catalog_size(const uint64_t catalog_size) {
106  }
107  void set_catalog_hash(const shash::Any &catalog_hash) {
109  }
112  }
113  void set_has_alt_catalog_path(const bool &has_alt_path) {
114  has_alt_catalog_path_ = has_alt_path;
115  }
117  void set_root_path(const std::string &root_path) {
118  root_path_ = shash::Md5(shash::AsciiPtr(root_path));
119  }
120  void set_reflog_hash(const shash::Any &checksum) { reflog_hash_ = checksum; }
121 
122  uint64_t revision() const { return revision_; }
123  std::string repository_name() const { return repository_name_; }
124  shash::Md5 root_path() const { return root_path_; }
126  uint64_t catalog_size() const { return catalog_size_; }
127  shash::Any certificate() const { return certificate_; }
128  shash::Any history() const { return history_; }
129  uint64_t publish_timestamp() const { return publish_timestamp_; }
130  bool garbage_collectable() const { return garbage_collectable_; }
132  shash::Any meta_info() const { return meta_info_; }
133  shash::Any reflog_hash() const { return reflog_hash_; }
134 
135  std::string MakeCatalogPath() const {
137  : ("data/" + catalog_hash_.MakePath());
138  }
139 
140  std::string MakeCertificatePath() const {
142  : ("data/" + certificate_.MakePath());
143  }
144 
145  private:
146  static Manifest *Load(const std::map<char, std::string> &content);
148  uint64_t catalog_size_;
150  uint32_t ttl_;
151  uint64_t revision_;
153  std::string repository_name_;
158 
165 
171 
176 }; // class Manifest
177 
178 } // namespace manifest
179 
180 #endif // CVMFS_MANIFEST_H_
void set_repository_name(const std::string &repository_name)
Definition: manifest.h:98
bool IsNull() const
Definition: hash.h:371
shash::Any micro_catalog_hash_
Definition: manifest.h:152
const manifest::Manifest * manifest() const
Definition: repository.h:125
bool Export(const std::string &path) const
Definition: manifest.cc:217
static Manifest * LoadMem(const unsigned char *buffer, const unsigned length)
Definition: manifest.cc:82
uint64_t timestamp
Definition: manifest.h:39
void set_catalog_hash(const shash::Any &catalog_hash)
Definition: manifest.h:107
std::string MakeAlternativePath() const
Definition: hash.h:313
shash::Any meta_info_
Definition: manifest.h:170
shash::Any catalog_hash
Definition: manifest.h:38
shash::Any certificate_
Definition: manifest.h:154
shash::Md5 root_path_
Definition: manifest.h:149
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:94
bool garbage_collectable_
Definition: manifest.h:157
static const uint64_t kInvalidRevision
Definition: manifest.h:23
void set_meta_info(const shash::Any &meta_info)
Definition: manifest.h:116
std::string ExportString() const
Definition: manifest.cc:185
void set_revision(const uint64_t revision)
Definition: manifest.h:93
shash::Any reflog_hash_
Definition: manifest.h:175
std::string MakeCertificatePath() const
Definition: manifest.h:140
bool has_alt_catalog_path() const
Definition: manifest.h:131
Algorithms algorithm
Definition: hash.h:122
uint64_t catalog_size() const
Definition: manifest.h:126
uint64_t revision() const
Definition: manifest.h:122
Algorithms
Definition: hash.h:41
uint64_t revision_
Definition: manifest.h:151
uint64_t revision
Definition: manifest.h:40
bool ExportBreadcrumb(const std::string &directory, const int mode) const
Definition: manifest.cc:239
uint64_t publish_timestamp() const
Definition: manifest.h:129
std::string repository_name() const
Definition: manifest.h:123
void set_publish_timestamp(const uint32_t publish_timestamp)
Definition: manifest.h:101
shash::Any certificate() const
Definition: manifest.h:127
shash::Any catalog_hash() const
Definition: manifest.h:125
bool garbage_collectable() const
Definition: manifest.h:130
bool has_alt_catalog_path_
Definition: manifest.h:164
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:153
void set_history(const shash::Any &history_db)
Definition: manifest.h:97
void set_garbage_collectability(const bool garbage_collectable)
Definition: manifest.h:110
void set_ttl(const uint32_t ttl)
Definition: manifest.h:92
shash::Algorithms GetHashAlgorithm() const
Definition: manifest.h:90
std::string ToString() const
Definition: manifest.cc:72
shash::Any history() const
Definition: manifest.h:128
void set_catalog_size(const uint64_t catalog_size)
Definition: manifest.h:104
shash::Md5 root_path() const
Definition: manifest.h:124
bool IsValid() const
Definition: manifest.h:33
std::string MakeCatalogPath() const
Definition: manifest.h:135
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:55
static Breadcrumb ReadBreadcrumb(const std::string &repo_name, const std::string &directory)
Definition: manifest.cc:249
void set_has_alt_catalog_path(const bool &has_alt_path)
Definition: manifest.h:113
shash::Any catalog_hash_
Definition: manifest.h:147
shash::Any reflog_hash() const
Definition: manifest.h:133
shash::Any history_
Definition: manifest.h:155
std::string MakePath() const
Definition: hash.h:306
uint64_t publish_timestamp_
Definition: manifest.h:156
void set_reflog_hash(const shash::Any &checksum)
Definition: manifest.h:120
uint64_t catalog_size_
Definition: manifest.h:148
static Manifest * LoadFile(const std::string &path)
Definition: manifest.cc:91
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:100
shash::Any meta_info() const
Definition: manifest.h:132
void set_root_path(const std::string &root_path)
Definition: manifest.h:117