5 #ifndef CVMFS_OBJECT_FETCHER_H_
6 #define CVMFS_OBJECT_FETCHER_H_
31 template <
class ConcreteObjectFetcherT>
53 texts[1] =
"object not found";
54 texts[2] =
"local I/O failure";
55 texts[3] =
"network failure";
56 texts[4] =
"decompression failed";
57 texts[5] =
"manifest name doesn't match";
58 texts[6] =
"manifest signature is invalid";
59 texts[7] =
"bad data received";
80 template <
class DerivedT>
101 return static_cast<DerivedT*
>(
this)->
FetchManifest(manifest);
118 shash::Any effective_history_hash = (!history_hash.IsNull())
121 if (effective_history_hash.
IsNull()) {
125 history_hash.IsNull());
129 const Failures retval =
Fetch(effective_history_hash, &path);
136 if (NULL == *history) {
140 (*history)->TakeDatabaseFileOwnership();
156 const std::string &catalog_path,
158 const bool is_nested =
false,
169 *catalog = CatalogTN::AttachFreely(catalog_path,
174 if (NULL == *catalog) {
178 (*catalog)->TakeDatabaseFileOwnership();
186 std::string tmp_path;
187 const bool decompress =
false;
188 const bool nocache =
true;
196 ReflogTN::HashDatabase(tmp_path, &computed_hash);
197 if (computed_hash != reflog_hash) {
198 unlink(tmp_path.c_str());
203 if (NULL == *reflog) {
207 (*reflog)->TakeDatabaseFileOwnership();
214 if (failure ==
kFailOk) *manifest = raw_manifest_ptr;
222 if (failure ==
kFailOk) *history = raw_history_ptr;
227 const std::string &catalog_path,
229 const bool is_nested =
false,
237 if (failure ==
kFailOk) *catalog = raw_catalog_ptr;
246 if (failure ==
kFailOk) *reflog = raw_reflog_ptr;
251 return static_cast<DerivedT*
>(
this)->
GetUrl(hash);
256 return !history_hash.
IsNull();
277 return static_cast<DerivedT*
>(
this)->
Fetch(object_hash, file_path);
281 const bool decompress,
283 std::string *file_path) {
284 return static_cast<DerivedT*
>(
this)->
Fetch(relative_path,
302 manifest->history().IsNull()) {
306 return manifest->history();
313 template <
class DerivedT>
316 template <
class DerivedT>
368 assert(file_path != NULL);
372 const bool decompress =
true;
373 const bool nocache =
false;
374 return Fetch(relative_path, decompress, nocache, file_path);
379 const bool decompress,
381 std::string *file_path) {
382 assert(file_path != NULL);
386 const std::string source =
BuildPath(relative_path);
389 relative_path.c_str());
399 "failed to create temp file '%s' (errno: %d)",
400 tmp_path.c_str(), errno);
405 const bool success = (decompress)
413 "to '%s' (errno: %d)",
414 source.c_str(), file_path->c_str(), errno);
415 unlink(file_path->c_str());
424 std::string
BuildPath(
const std::string &relative_path)
const {
436 template <
class CatalogT,
class HistoryT,
class ReflogT>
476 const std::string &repo_url,
509 "repository name mismatch. No name provided?");
516 "repository signature mismatch. No key(s) provided?");
521 "failed to load manifest (%d - %s)",
537 assert(object_file != NULL);
540 const bool decompress =
true;
541 const bool nocache =
false;
543 return Download(url, decompress, nocache, &object_hash, object_file);
547 const bool decompress,
549 std::string *file_path) {
551 return Download(relative_path, decompress, nocache, expected_hash,
556 std::string
BuildUrl(
const std::string &relative_path)
const {
565 const bool decompress,
568 std::string *file_path) {
577 "failed to create temp file '%s' (errno: %d)",
578 tmp_path.c_str(), errno);
583 const std::string url =
BuildUrl(relative_path);
584 const bool probe_hosts =
false;
596 "%s to '%s' (%d - %s)",
597 relative_path.c_str(), file_path->c_str(),
599 unlink(file_path->c_str());
612 "HTTP connection error %d: %s", retval, url.c_str());
620 "HTTP protocol error %d: %s (%d)",
621 download_job.
http_code(), url.c_str(), retval);
633 "HTTP transfer error %d (HTTP code %d): %s",
634 retval, download_job.
http_code(), url.c_str());
652 template <
class CatalogT,
class HistoryT,
class ReflogT>
659 #endif // CVMFS_OBJECT_FETCHER_H_
const char * Code2Ascii(const ObjectFetcherFailures::Failures error)
const manifest::Manifest * manifest() const
SharedPtr< string > temp_dir
NameString GetFileName(const PathString &path)
ObjectFetcherFailures::Failures Failures
Failures Fetch(const shash::Any &object_hash, std::string *file_path)
FILE * CreateTempFile(const std::string &path_prefix, const int mode, const char *open_flags, std::string *final_path)
const history::History * history() const
Failures FetchReflog(const shash::Any &reflog_hash, ReflogTN **reflog)
std::string BuildRelativeUrl(const shash::Any &hash) const
Failures FetchHistory(HistoryTN **history, const shash::Any &history_hash=shash::Any())
const std::string temporary_directory_
Failures FetchManifest(UniquePtr< manifest::Manifest > *manifest)
Failures FetchManifest(manifest::Manifest **manifest)
assert((mem||(size==0))&&"Out Of Memory")
Failures FetchReflog(const shash::Any &reflog_hash, UniquePtr< ReflogTN > *reflog)
shash::Any GetHistoryHash()
object_fetcher_traits< DerivedT >::ReflogTN ReflogTN
std::string BuildUrl(const std::string &relative_path) const
std::string BuildPath(const std::string &relative_path) const
bool CopyPath2File(const std::string &src, FILE *fdest)
const std::string repo_name_
bool FileExists(const std::string &path)
AbstractObjectFetcher< ThisTN > BaseTN
BaseTN::Failures Failures
object_fetcher_traits< DerivedT >::CatalogTN CatalogTN
Failures Fetch(const std::string &relative_path, const bool decompress, const bool nocache, std::string *file_path)
std::string GetUrl(const shash::Any &hash) const
void SetForceNocache(bool force_nocache)
signature::SignatureManager * signature_manager_
const char kSuffixCatalog
Failures FetchCatalog(const shash::Any &catalog_hash, const std::string &catalog_path, CatalogTN **catalog, const bool is_nested=false, CatalogTN *parent=NULL)
Failures Fetch(const std::string &base_url, const std::string &repository_name, const uint64_t minimum_timestamp, const shash::Any *base_catalog, signature::SignatureManager *signature_manager, download::DownloadManager *download_manager, ManifestEnsemble *ensemble)
bool DecompressPath2File(const string &src, FILE *fdest)
const signature::SignatureManager * signature_mgr() const
const std::string repo_url_
bool IsProxyTransferError(const Failures error)
download::DownloadManager * download_manager_
object_fetcher_traits< DerivedT >::HistoryTN HistoryTN
HttpObjectFetcher< CatalogT, HistoryT, ReflogT > ThisTN
BaseTN::Failures Failures
manifest::Reflog * reflog
HttpObjectFetcher(const std::string &repo_name, const std::string &repo_url, const std::string &temp_dir, download::DownloadManager *download_mgr, signature::SignatureManager *signature_mgr)
Failures FetchCatalog(const shash::Any &catalog_hash, const std::string &catalog_path, UniquePtr< CatalogTN > *catalog, const bool is_nested=false, CatalogTN *parent=NULL)
const std::string base_path_
const char kSuffixHistory
AbstractObjectFetcher< ThisTN > BaseTN
LocalObjectFetcher< CatalogT, HistoryT, ReflogT > ThisTN
static const std::string kReflogFilename
Failures Fetch(JobInfo *info)
LocalObjectFetcher(const std::string &base_path, const std::string &temp_dir)
Failures FetchManifest(manifest::Manifest **manifest)
Failures FetchHistory(UniquePtr< HistoryTN > *history, const shash::Any &history_hash=shash::Any())
Failures FetchManifest(manifest::Manifest **manifest)
Failures Download(const std::string &relative_path, const bool decompress, const bool nocache, const shash::Any *expected_hash, std::string *file_path)
bool IsHostTransferError(const Failures error)
Failures Fetch(const shash::Any &object_hash, std::string *object_file)
Failures Fetch(const std::string &relative_path, const bool decompress, const bool, std::string *file_path)
std::string GetUrl(const shash::Any &hash) const
static const std::string kManifestFilename
std::string MakePath() const
Failures Fetch(const std::string &relative_path, const bool decompress, const bool nocache, std::string *file_path)
static Manifest * LoadFile(const std::string &path)
Failures Fetch(const shash::Any &object_hash, std::string *file_path)
const std::string & temporary_directory() const
AbstractObjectFetcher(const std::string &temp_dir)
std::string BuildRelativePath(const shash::Any &hash) const
std::string GetUrl(const shash::Any &hash) const
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)