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(
170 catalog_path, path, catalog_hash, parent, is_nested);
171 if (NULL == *catalog) {
175 (*catalog)->TakeDatabaseFileOwnership();
183 std::string tmp_path;
184 const bool decompress =
false;
185 const bool nocache =
true;
193 ReflogTN::HashDatabase(tmp_path, &computed_hash);
194 if (computed_hash != reflog_hash) {
195 unlink(tmp_path.c_str());
200 if (NULL == *reflog) {
204 (*reflog)->TakeDatabaseFileOwnership();
212 *manifest = raw_manifest_ptr;
221 *history = raw_history_ptr;
226 const std::string &catalog_path,
228 const bool is_nested =
false,
232 catalog_hash, catalog_path, &raw_catalog_ptr, is_nested, parent);
234 *catalog = raw_catalog_ptr;
243 *reflog = raw_reflog_ptr;
248 return static_cast<DerivedT *
>(
this)->
GetUrl(hash);
253 return !history_hash.
IsNull();
274 return static_cast<DerivedT *
>(
this)->
Fetch(object_hash, file_path);
278 const bool decompress,
280 std::string *file_path) {
281 return static_cast<DerivedT *
>(
this)->
Fetch(
282 relative_path, decompress, nocache, file_path);
296 || manifest->history().IsNull()) {
300 return manifest->history();
307 template<
class DerivedT>
310 template<
class DerivedT>
325 LocalObjectFetcher<CatalogT, HistoryT, ReflogT> > {
359 assert(file_path != NULL);
363 const bool decompress =
true;
364 const bool nocache =
false;
365 return Fetch(relative_path, decompress, nocache, file_path);
370 const bool decompress,
372 std::string *file_path) {
373 assert(file_path != NULL);
380 relative_path.c_str());
390 "failed to create temp file '%s' (errno: %d)", tmp_path.c_str(),
403 "failed to fetch file from '%s' "
404 "to '%s' (errno: %d)",
405 source.c_str(), file_path->c_str(), errno);
406 unlink(file_path->c_str());
415 std::string
BuildPath(
const std::string &relative_path)
const {
427 template<
class CatalogT,
class HistoryT,
class ReflogT>
444 HttpObjectFetcher<CatalogT, HistoryT, ReflogT> > {
466 const std::string &repo_url,
498 "repository name mismatch. No name provided?");
505 "repository signature mismatch. No key(s) provided?");
524 assert(object_file != NULL);
527 const bool decompress =
true;
528 const bool nocache =
false;
530 return Download(url, decompress, nocache, &object_hash, object_file);
534 const bool decompress,
536 std::string *file_path) {
538 return Download(relative_path, decompress, nocache, expected_hash,
543 std::string
BuildUrl(
const std::string &relative_path)
const {
552 const bool decompress,
555 std::string *file_path) {
564 "failed to create temp file '%s' (errno: %d)", tmp_path.c_str(),
570 const std::string url =
BuildUrl(relative_path);
571 const bool probe_hosts =
false;
583 "failed to download file "
584 "%s to '%s' (%d - %s)",
585 relative_path.c_str(), file_path->c_str(), retval,
587 unlink(file_path->c_str());
600 "HTTP connection error %d: %s", retval, url.c_str());
608 "HTTP protocol error %d: %s (%d)", download_job.
http_code(),
609 url.c_str(), retval);
620 "HTTP transfer error %d (HTTP code %d): %s", retval,
639 template<
class CatalogT,
class HistoryT,
class ReflogT>
646 #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)
CVMFS_EXPORT const LogSource source
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,...)