19 namespace swissknife {
23 r.push_back(Parameter::Mandatory(
'r',
"repository url / local storage path"));
24 r.push_back(Parameter::Mandatory(
'n',
"fully qualified repository name"));
25 r.push_back(Parameter::Optional(
'R',
"path to reflog.chksum file"));
26 r.push_back(Parameter::Optional(
'k',
"repository master key(s) / dir"));
27 r.push_back(Parameter::Optional(
't',
"temporary directory"));
28 r.push_back(Parameter::Optional(
'o',
"output file"));
29 r.push_back(Parameter::Optional(
'@',
"proxy url"));
34 const string &repo_url = *args.find(
'r')->second;
35 const string &repo_name = *args.find(
'n')->second;
36 const std::string &reflog_chksum_path = (args.count(
'R') > 0) ?
37 *args.find(
'R')->second :
"";
38 string repo_keys = (args.count(
'k') > 0) ?
39 *args.find(
'k')->second :
"";
42 const string temp_directory = (args.count(
't') > 0) ?
43 *args.find(
't')->second :
"/tmp";
44 const string output_path = (args.count(
'o') > 0) ?
45 *args.find(
'o')->second :
"";
48 if (reflog_chksum_path !=
"") {
55 const bool follow_redirects =
false;
56 const string proxy = (args.count(
'@') > 0) ? *args.find(
'@')->second :
"";
57 if (!this->InitDownloadManager(follow_redirects, proxy) ||
58 !this->InitSignatureManager(repo_keys)) {
70 if (reflog_hash.
IsNull()) {
84 success = Run(&object_fetcher, repo_name, output_path, reflog_hash);
87 success = Run(&object_fetcher, repo_name, output_path, reflog_hash);
90 return (success) ? 0 : 1;
93 template <
class ObjectFetcherT>
94 bool CommandListReflog::Run(ObjectFetcherT *object_fetcher,
string repo_name,
97 typename ObjectFetcherT::ReflogTN *
reflog;
98 reflog = FetchReflog(object_fetcher, repo_name, reflog_hash);
102 objects_->
Init(1024, null_hash, hasher);
105 vector<shash::Any> catalogs;
117 vector<shash::Any>::iterator i = catalogs.begin();
118 const vector<shash::Any>::const_iterator iend = catalogs.end();
119 for (; i != iend && success; i++) {
126 "Catalog traversal aborted due to an error");
131 vector<shash::Any> histories, certificates, metainfos;
134 "Failed to fetch history objects from reflog");
139 "Failed to fetch certificate objects from reflog");
144 "Failed to fetch metainfo objects from reflog");
147 InsertObjects(histories);
148 InsertObjects(certificates);
149 InsertObjects(metainfos);
156 if (output_path ==
"") {
159 int fd = open(output_path.c_str(), O_WRONLY | O_CREAT, 0644);
161 FILE *stream = fdopen(fd,
"w");
169 void CommandListReflog::CatalogCallback(
176 InsertObjects(referenced_hashes);
181 void CommandListReflog::InsertObjects(
const vector<shash::Any> &list) {
182 vector<shash::Any>::const_iterator i = list.begin();
183 const vector<shash::Any>::const_iterator iend = list.end();
184 for (; i != iend; ++i) {
185 if ((*i) != objects_->empty_key())
186 objects_->Insert(*i,
true);
190 void CommandListReflog::DumpObjects(FILE *stream)
194 for (uint32_t i = 0; i < objects_->capacity(); ++i) {
195 if (hashes[i] != empty_key) {
196 fprintf(stream,
"%s\n", hashes[i].ToString().c_str());
const char * Code2Ascii(const ObjectFetcherFailures::Failures error)
CallbackPtr RegisterListener(typename BoundClosure< CatalogTraversalData< ObjectFetcherT::CatalogTN >, DelegateT, ClosureDataT >::CallbackMethod method, DelegateT *delegate, ClosureDataT data)
const manifest::Manifest * manifest() const
void CatalogCallback(const CatalogTraversalData< catalog::Catalog > &data)
static bool ReadChecksum(const std::string &path, shash::Any *checksum)
std::vector< Parameter > ParameterList
string JoinStrings(const vector< string > &strings, const string &joint)
bool IsHttpUrl(const std::string &path)
ObjectFetcherT * object_fetcher
assert((mem||(size==0))&&"Out Of Memory")
std::vector< shash::Any > HashVector
const HashVector & GetReferencedObjects() const
PathString mountpoint() const
manifest::Reflog * reflog
bool DirectoryExists(const std::string &path)
bool TraverseRevision(const shash::Any &root_catalog_hash, const TraversalType type=Base::kBreadthFirst)
std::map< char, SharedPtr< std::string > > ArgumentList
Failures FetchManifest(manifest::Manifest **manifest)
shash::Any reflog_hash() const
void Init(uint32_t expected_size, Key empty, uint32_t(*hasher)(const Key &key))
const char * c_str() const
std::vector< std::string > FindFilesBySuffix(const std::string &dir, const std::string &suffix)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)