CernVM-FS  2.12.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 "network/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 
34  FILE *fcatalog = CreateTempFile(dir_temp_ + "/catalog", 0666, "w",
35  catalog_path);
36  if (!fcatalog) {
37  PANIC(kLogStderr, "failed to create temp file when loading %s",
38  url.c_str());
39  }
40 
41  cvmfs::FileSink filesink(fcatalog);
42  download::JobInfo download_catalog(&url, true, false,
43  &effective_hash, &filesink);
44  download::Failures retval = download_manager_->Fetch(&download_catalog);
45  fclose(fcatalog);
46 
47  if (retval != download::kFailOk) {
48  unlink(catalog_path->c_str());
49  PANIC(kLogStderr, "failed to load %s from Stratum 0 (%d - %s)", url.c_str(),
50  retval, download::Code2Ascii(retval));
51  }
52 
53  *catalog_hash = effective_hash;
54  return kLoadNew;
55 }
56 
57 
58 Catalog* SimpleCatalogManager::CreateCatalog(const PathString &mountpoint,
59  const shash::Any &catalog_hash,
60  Catalog *parent_catalog)
61 {
62  Catalog *new_catalog = new Catalog(mountpoint, catalog_hash, parent_catalog);
63  if (manage_catalog_files_) {
64  new_catalog->TakeDatabaseFileOwnership();
65  }
66 
67  return new_catalog;
68 }
69 
70 } // namespace catalog
bool IsNull() const
Definition: hash.h:383
#define PANIC(...)
Definition: exception.h:29
FILE * CreateTempFile(const std::string &path_prefix, const int mode, const char *open_flags, std::string *final_path)
Definition: posix.cc:1005
assert((mem||(size==0))&&"Out Of Memory")
const char * Code2Ascii(const Failures error)
const char kSuffixCatalog
Definition: hash.h:54
void TakeDatabaseFileOwnership()
Definition: catalog.cc:479
Suffix suffix
Definition: hash.h:126
std::string MakePath() const
Definition: hash.h:316