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 
17 // TODO(herethebedragons) correct return value and root_ctlg_location?
18 LoadReturn SimpleCatalogManager::GetNewRootCatalogContext(
19  CatalogContext *result) {
20  if (result->hash().IsNull()) {
21  result->SetHash(base_hash_);
22  }
24  result->SetMountpoint(PathString("", 0));
25 
26  return kLoadNew;
27 }
28 
29 
36 LoadReturn SimpleCatalogManager::LoadCatalogByHash(
37  CatalogContext *ctlg_context) {
38  const shash::Any effective_hash = ctlg_context->hash();
39  assert(shash::kSuffixCatalog == effective_hash.suffix);
40  const string url = stratum0_ + "/data/" + effective_hash.MakePath();
41 
42  std::string tmp;
43 
44  FILE *fcatalog = CreateTempFile(dir_temp_ + "/catalog", 0666, "w", &tmp);
45  ctlg_context->SetSqlitePath(tmp);
46  if (!fcatalog) {
47  PANIC(kLogStderr, "failed to create temp file when loading %s",
48  url.c_str());
49  }
50 
51  cvmfs::FileSink filesink(fcatalog);
52  download::JobInfo download_catalog(&url, true, false,
53  &effective_hash, &filesink);
54  const download::Failures retval = download_manager_->Fetch(&download_catalog);
55  fclose(fcatalog);
56 
57  if (retval != download::kFailOk) {
58  unlink(ctlg_context->GetSqlitePathPtr()->c_str());
59  PANIC(kLogStderr, "failed to load %s from Stratum 0 (%d - %s)",
60  url.c_str(), retval, download::Code2Ascii(retval));
61  }
62 
63  return kLoadNew;
64 }
65 
66 
67 Catalog* SimpleCatalogManager::CreateCatalog(const PathString &mountpoint,
68  const shash::Any &catalog_hash,
69  Catalog *parent_catalog)
70 {
71  Catalog *new_catalog = new Catalog(mountpoint, catalog_hash, parent_catalog);
72  if (manage_catalog_files_) {
73  new_catalog->TakeDatabaseFileOwnership();
74  }
75 
76  return new_catalog;
77 }
78 
79 } // namespace catalog
shash::Any hash() const
Definition: catalog_mgr.h:125
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")
void SetMountpoint(const PathString &mountpoint)
Definition: catalog_mgr.h:135
const char * Code2Ascii(const Failures error)
const char kSuffixCatalog
Definition: hash.h:54
void TakeDatabaseFileOwnership()
Definition: catalog.cc:479
void SetRootCtlgLocation(RootCatalogLocation root_ctlg_location)
Definition: catalog_mgr.h:140
std::string * GetSqlitePathPtr()
Definition: catalog_mgr.h:122
ShortString< kDefaultMaxPath, 0 > PathString
Definition: shortstring.h:217
void SetHash(shash::Any hash)
Definition: catalog_mgr.h:134
Suffix suffix
Definition: hash.h:126
std::string MakePath() const
Definition: hash.h:316
void SetSqlitePath(const std::string &sqlite_path)
Definition: catalog_mgr.h:136