19 Breadcrumb::Breadcrumb(
const std::string &from_string) {
23 if (from_string.empty()) {
28 std::vector<std::string> vec_split_timestamp =
SplitString(from_string,
'T');
33 if (vec_split_timestamp.size() > 1) {
35 std::vector<std::string> vec_split_revision =
42 if (vec_split_revision.size() > 1) {
48 bool Breadcrumb::Export(
const string &fqrn,
const string &directory,
49 const int mode)
const {
51 "/cvmfschecksum." + fqrn;
53 FILE *fbreadcrumb =
CreateTempFile(breadcrumb_path, mode,
"w", &tmp_path);
54 if (fbreadcrumb == NULL)
56 string str_breadcrumb = ToString();
57 int written = fwrite(&(str_breadcrumb[0]), 1, str_breadcrumb.length(),
60 if (static_cast<unsigned>(written) != str_breadcrumb.length()) {
61 unlink(tmp_path.c_str());
64 int retval = rename(tmp_path.c_str(), breadcrumb_path.c_str());
66 unlink(tmp_path.c_str());
72 std::string Breadcrumb::ToString()
const {
73 return catalog_hash.ToString()
82 Manifest *Manifest::LoadMem(
const unsigned char *buffer,
83 const unsigned length)
85 map<char, string> content;
92 Manifest *Manifest::LoadFile(
const std::string &from_path) {
93 map<char, string> content;
101 Manifest *Manifest::Load(
const map<char, string> &content) {
102 map<char, string>::const_iterator iter;
110 iter = content.find(
'C');
111 if ((iter = content.find(
'C')) == content.end())
115 if ((iter = content.find(
'R')) == content.end())
118 if ((iter = content.find(
'D')) == content.end())
121 if ((iter = content.find(
'S')) == content.end())
127 uint64_t catalog_size = 0;
129 string repository_name;
132 uint64_t publish_timestamp = 0;
133 bool garbage_collectable =
false;
134 bool has_alt_catalog_path =
false;
138 if ((iter = content.find(
'B')) != content.end())
140 if ((iter = content.find(
'L')) != content.end())
143 if ((iter = content.find(
'N')) != content.end())
144 repository_name = iter->second;
145 if ((iter = content.find(
'X')) != content.end())
148 if ((iter = content.find(
'H')) != content.end())
151 if ((iter = content.find(
'T')) != content.end())
153 if ((iter = content.find(
'G')) != content.end())
154 garbage_collectable = (iter->second ==
"yes");
155 if ((iter = content.find(
'A')) != content.end())
156 has_alt_catalog_path = (iter->second ==
"yes");
157 if ((iter = content.find(
'M')) != content.end())
160 if ((iter = content.find(
'Y')) != content.end()) {
164 return new Manifest(catalog_hash, catalog_size, root_path, ttl, revision,
165 micro_catalog_hash, repository_name, certificate,
166 history, publish_timestamp, garbage_collectable,
167 has_alt_catalog_path, meta_info, reflog_hash);
171 Manifest::Manifest(
const shash::Any &catalog_hash,
172 const uint64_t catalog_size,
173 const string &root_path)
174 : catalog_hash_(catalog_hash)
175 , catalog_size_(catalog_size)
176 , root_path_(shash::Md5(shash::AsciiPtr(root_path)))
177 , ttl_(catalog::Catalog::kDefaultTTL)
179 , publish_timestamp_(0)
180 , garbage_collectable_(false)
181 , has_alt_catalog_path_(false)
224 FILE *fmanifest = fopen(path.c_str(),
"w");
230 if (fwrite(manifest.data(), 1, manifest.length(), fmanifest) !=
234 unlink(path.c_str());
257 const std::string &repo_name,
258 const std::string &directory)
261 const string breadcrumb_path = directory +
"/cvmfschecksum." + repo_name;
262 FILE *fbreadcrumb = fopen(breadcrumb_path.c_str(),
"r");
268 const size_t read_bytes = fread(tmp, 1, 164, fbreadcrumb);
269 if (read_bytes > 0) {
270 breadcrumb =
Breadcrumb(std::string(tmp, read_bytes));
shash::Any micro_catalog_hash_
const manifest::Manifest * manifest() const
bool Export(const std::string &path) const
FILE * CreateTempFile(const std::string &path_prefix, const int mode, const char *open_flags, std::string *final_path)
const char kSuffixCertificate
std::string ToString(const bool with_suffix=false) const
const history::History * history() const
bool garbage_collectable_
const char kSuffixMicroCatalog
std::string ExportString() const
std::string StringifyUint(const uint64_t value)
string StringifyBool(const bool value)
bool ExportBreadcrumb(const std::string &directory, const int mode) const
vector< string > SplitString(const string &str, char delim)
const char kSuffixCatalog
string StringifyInt(const int64_t value)
const char kSuffixMetainfo
bool has_alt_catalog_path_
std::string repository_name_
const char kSuffixHistory
uint64_t String2Uint64(const string &value)
bool ParseKeyvalPath(const string &filename, map< char, string > *content)
Any MkFromHexPtr(const HexPtr hex, const char suffix)
std::string meta_info() const
static Breadcrumb ReadBreadcrumb(const std::string &repo_name, const std::string &directory)
std::string MakeCanonicalPath(const std::string &path)
uint64_t publish_timestamp_
void ParseKeyvalMem(const unsigned char *buffer, const unsigned buffer_size, map< char, string > *content)