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 "hash.h" |
14 |
|
|
#include "history.h" |
15 |
|
|
|
16 |
|
|
namespace manifest { |
17 |
|
|
|
18 |
|
|
/** |
19 |
|
|
* The Manifest is the bootstrap snippet for a repository. It is stored in |
20 |
|
|
* .cvmfspublished. |
21 |
|
|
*/ |
22 |
|
255 |
class Manifest { |
23 |
|
|
public: |
24 |
|
|
static Manifest *LoadFile(const std::string &path); |
25 |
|
|
static Manifest *LoadMem(const unsigned char *buffer, const unsigned length); |
26 |
|
|
Manifest(const shash::Any &catalog_hash, |
27 |
|
|
const uint64_t catalog_size, |
28 |
|
|
const std::string &root_path); |
29 |
|
44 |
Manifest(const shash::Any &catalog_hash, |
30 |
|
|
const uint64_t catalog_size, |
31 |
|
|
const shash::Md5 &root_path, |
32 |
|
|
const uint32_t ttl, |
33 |
|
|
const uint64_t revision, |
34 |
|
|
const shash::Any µ_catalog_hash, |
35 |
|
|
const std::string &repository_name, |
36 |
|
|
const shash::Any certificate, |
37 |
|
|
const shash::Any history, |
38 |
|
|
const uint64_t publish_timestamp, |
39 |
|
|
const bool garbage_collectable, |
40 |
|
|
const bool has_alt_catalog_path, |
41 |
|
|
const shash::Any &meta_info) |
42 |
|
|
: catalog_hash_(catalog_hash) |
43 |
|
|
, catalog_size_(catalog_size) |
44 |
|
|
, root_path_(root_path) |
45 |
|
|
, ttl_(ttl) |
46 |
|
|
, revision_(revision) |
47 |
|
|
, micro_catalog_hash_(micro_catalog_hash) |
48 |
|
|
, repository_name_(repository_name) |
49 |
|
|
, certificate_(certificate) |
50 |
|
|
, history_(history) |
51 |
|
|
, publish_timestamp_(publish_timestamp) |
52 |
|
|
, garbage_collectable_(garbage_collectable) |
53 |
|
|
, has_alt_catalog_path_(has_alt_catalog_path) |
54 |
|
44 |
, meta_info_(meta_info) { } |
55 |
|
|
|
56 |
|
|
std::string ExportString() const; |
57 |
|
|
bool Export(const std::string &path) const; |
58 |
|
|
bool ExportChecksum(const std::string &directory, const int mode) const; |
59 |
|
|
static bool ReadChecksum(const std::string &repo_name, |
60 |
|
|
const std::string &directory, |
61 |
|
|
shash::Any *hash, |
62 |
|
|
uint64_t *last_modified); |
63 |
|
|
|
64 |
|
20 |
shash::Algorithms GetHashAlgorithm() const { return catalog_hash_.algorithm; } |
65 |
|
|
|
66 |
|
8 |
void set_ttl(const uint32_t ttl) { ttl_ = ttl; } |
67 |
|
8 |
void set_revision(const uint64_t revision) { revision_ = revision; } |
68 |
|
40 |
void set_certificate(const shash::Any &certificate) { |
69 |
✗✓ |
40 |
certificate_ = certificate; |
70 |
|
40 |
} |
71 |
|
195 |
void set_history(const shash::Any &history_db) { |
72 |
✗✓ |
195 |
history_ = history_db; |
73 |
|
195 |
} |
74 |
|
40 |
void set_repository_name(const std::string &repository_name) { |
75 |
|
40 |
repository_name_ = repository_name; |
76 |
|
40 |
} |
77 |
|
20 |
void set_publish_timestamp(const uint32_t publish_timestamp) { |
78 |
|
20 |
publish_timestamp_ = publish_timestamp; |
79 |
|
20 |
} |
80 |
|
8 |
void set_catalog_size(const uint64_t catalog_size) { |
81 |
|
8 |
catalog_size_ = catalog_size; |
82 |
|
8 |
} |
83 |
|
8 |
void set_catalog_hash(const shash::Any &catalog_hash) { |
84 |
✗✓ |
8 |
catalog_hash_ = catalog_hash; |
85 |
|
8 |
} |
86 |
|
|
void set_garbage_collectability(const bool garbage_collectable) { |
87 |
|
|
garbage_collectable_ = garbage_collectable; |
88 |
|
|
} |
89 |
|
|
void set_has_alt_catalog_path(const bool &has_alt_path) { |
90 |
|
|
has_alt_catalog_path_ = has_alt_path; |
91 |
|
|
} |
92 |
|
|
void set_meta_info(const shash::Any &meta_info) { |
93 |
|
|
meta_info_ = meta_info; |
94 |
|
|
} |
95 |
|
8 |
void set_root_path(const std::string &root_path) { |
96 |
✗✓ |
8 |
root_path_ = shash::Md5(shash::AsciiPtr(root_path)); |
97 |
|
8 |
} |
98 |
|
|
|
99 |
|
|
uint64_t revision() const { return revision_; } |
100 |
|
38 |
std::string repository_name() const { return repository_name_; } |
101 |
|
34 |
shash::Md5 root_path() const { return root_path_; } |
102 |
|
268 |
shash::Any catalog_hash() const { return catalog_hash_; } |
103 |
|
|
uint64_t catalog_size() const { return catalog_size_; } |
104 |
|
43 |
shash::Any certificate() const { return certificate_; } |
105 |
|
142 |
shash::Any history() const { return history_; } |
106 |
|
34 |
uint64_t publish_timestamp() const { return publish_timestamp_; } |
107 |
|
|
bool garbage_collectable() const { return garbage_collectable_; } |
108 |
|
11 |
bool has_alt_catalog_path() const { return has_alt_catalog_path_; } |
109 |
|
|
shash::Any meta_info() const { return meta_info_; } |
110 |
|
|
|
111 |
|
|
std::string MakeCatalogPath() const { |
112 |
|
|
return has_alt_catalog_path_ ? catalog_hash_.MakeAlternativePath() : |
113 |
|
|
("data/" + catalog_hash_.MakePath()); |
114 |
|
|
} |
115 |
|
|
|
116 |
|
32 |
std::string MakeCertificatePath() const { |
117 |
|
|
return has_alt_catalog_path_ ? |
118 |
✗✓✗✗ ✓✗ |
32 |
certificate_.MakeAlternativePath() : ("data/" + certificate_.MakePath()); |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
private: |
122 |
|
|
static Manifest *Load(const std::map<char, std::string> &content); |
123 |
|
|
shash::Any catalog_hash_; |
124 |
|
|
uint64_t catalog_size_; |
125 |
|
|
shash::Md5 root_path_; |
126 |
|
|
uint32_t ttl_; |
127 |
|
|
uint64_t revision_; |
128 |
|
|
shash::Any micro_catalog_hash_; |
129 |
|
|
std::string repository_name_; |
130 |
|
|
shash::Any certificate_; |
131 |
|
|
shash::Any history_; |
132 |
|
|
uint64_t publish_timestamp_; |
133 |
|
|
bool garbage_collectable_; |
134 |
|
|
|
135 |
|
|
/** |
136 |
|
|
* The root catalog and the certifacte might be available as .cvmfscatalog and |
137 |
|
|
* .cvmfscertificate. That is helpful if the data subdirectory is protected |
138 |
|
|
* on the web server. |
139 |
|
|
*/ |
140 |
|
|
bool has_alt_catalog_path_; |
141 |
|
|
|
142 |
|
|
/** |
143 |
|
|
* Hash of a JSON object that describes the repository (owner, purpose, list |
144 |
|
|
* of recommended stratum 1s, ...) |
145 |
|
|
*/ |
146 |
|
|
shash::Any meta_info_; |
147 |
|
|
}; // class Manifest |
148 |
|
|
|
149 |
|
|
} // namespace manifest |
150 |
|
|
|
151 |
|
|
#endif // CVMFS_MANIFEST_H_ |