CernVM-FS  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
catalog_mgr_ro.cc
Go to the documentation of this file.
1 
5 #include "cvmfs_config.h"
6 #include "catalog_mgr_ro.h"
7 
8 #include "compression.h"
9 #include "download.h"
10 #include "util/exception.h"
11 #include "util/posix.h"
12 
13 using namespace std; // NOLINT
14 
15 namespace catalog {
16 
25 LoadError SimpleCatalogManager::LoadCatalog(const PathString &mountpoint,
26  const shash::Any &hash,
27  std::string *catalog_path,
28  shash::Any *catalog_hash)
29 {
30  shash::Any effective_hash = hash.IsNull() ? base_hash_ : hash;
31  assert(shash::kSuffixCatalog == effective_hash.suffix);
32  const string url = stratum0_ + "/data/" + effective_hash.MakePath();
33  FILE *fcatalog = CreateTempFile(dir_temp_ + "/catalog", 0666, "w",
34  catalog_path);
35  if (!fcatalog) {
36  PANIC(kLogStderr, "failed to create temp file when loading %s",
37  url.c_str());
38  }
39 
40  download::JobInfo download_catalog(&url, true, false, fcatalog,
41  &effective_hash);
42  download::Failures retval = download_manager_->Fetch(&download_catalog);
43  fclose(fcatalog);
44 
45  if (retval != download::kFailOk) {
46  unlink(catalog_path->c_str());
47  PANIC(kLogStderr, "failed to load %s from Stratum 0 (%d - %s)", url.c_str(),
48  retval, download::Code2Ascii(retval));
49  }
50 
51  *catalog_hash = effective_hash;
52  return kLoadNew;
53 }
54 
55 
56 Catalog* SimpleCatalogManager::CreateCatalog(const PathString &mountpoint,
57  const shash::Any &catalog_hash,
58  Catalog *parent_catalog)
59 {
60  Catalog *new_catalog = new Catalog(mountpoint, catalog_hash, parent_catalog);
61  if (manage_catalog_files_) {
62  new_catalog->TakeDatabaseFileOwnership();
63  }
64 
65  return new_catalog;
66 }
67 
68 } // namespace catalog
bool IsNull() const
Definition: hash.h:379
#define PANIC(...)
Definition: exception.h:26
FILE * CreateTempFile(const std::string &path_prefix, const int mode, const char *open_flags, std::string *final_path)
Definition: posix.cc:1025
assert((mem||(size==0))&&"Out Of Memory")
const char * Code2Ascii(const Failures error)
Definition: download.h:86
const char kSuffixCatalog
Definition: hash.h:52
void TakeDatabaseFileOwnership()
Definition: catalog.cc:479
Suffix suffix
Definition: hash.h:124
std::string MakePath() const
Definition: hash.h:312