1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM file system. |
3 |
|
|
*/ |
4 |
|
|
|
5 |
|
|
#include "cvmfs_config.h" |
6 |
|
|
#include "catalog_mgr_ro.h" |
7 |
|
|
|
8 |
|
|
#include "compression.h" |
9 |
|
|
#include "download.h" |
10 |
|
|
#include "util/posix.h" |
11 |
|
|
|
12 |
|
|
using namespace std; // NOLINT |
13 |
|
|
|
14 |
|
|
namespace catalog { |
15 |
|
|
|
16 |
|
|
/** |
17 |
|
|
* Loads a catalog via HTTP from Statum 0 into a temporary file. |
18 |
|
|
* @param url_path the url of the catalog to load |
19 |
|
|
* @param mount_point the file system path where the catalog should be mounted |
20 |
|
|
* @param catalog_file a pointer to the string containing the full qualified |
21 |
|
|
* name of the catalog afterwards |
22 |
|
|
* @return 0 on success, different otherwise |
23 |
|
|
*/ |
24 |
|
18 |
LoadError SimpleCatalogManager::LoadCatalog(const PathString &mountpoint, |
25 |
|
|
const shash::Any &hash, |
26 |
|
|
std::string *catalog_path, |
27 |
|
|
shash::Any *catalog_hash) |
28 |
|
|
{ |
29 |
✓✓ |
18 |
shash::Any effective_hash = hash.IsNull() ? base_hash_ : hash; |
30 |
✗✓ |
18 |
assert(shash::kSuffixCatalog == effective_hash.suffix); |
31 |
|
18 |
const string url = stratum0_ + "/data/" + effective_hash.MakePath(); |
32 |
|
|
FILE *fcatalog = CreateTempFile(dir_temp_ + "/catalog", 0666, "w", |
33 |
|
18 |
catalog_path); |
34 |
✗✓ |
18 |
if (!fcatalog) { |
35 |
|
|
LogCvmfs(kLogCatalog, kLogStderr, |
36 |
|
|
"failed to create temp file when loading %s", url.c_str()); |
37 |
|
|
assert(false); |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
download::JobInfo download_catalog(&url, true, false, fcatalog, |
41 |
|
18 |
&effective_hash); |
42 |
|
18 |
download::Failures retval = download_manager_->Fetch(&download_catalog); |
43 |
|
18 |
fclose(fcatalog); |
44 |
|
|
|
45 |
✗✓ |
18 |
if (retval != download::kFailOk) { |
46 |
|
|
LogCvmfs(kLogCatalog, kLogStderr, |
47 |
|
|
"failed to load %s from Stratum 0 (%d - %s)", url.c_str(), |
48 |
|
|
retval, download::Code2Ascii(retval)); |
49 |
|
|
unlink(catalog_path->c_str()); |
50 |
|
|
assert(false); |
51 |
|
|
} |
52 |
|
|
|
53 |
✗✓ |
18 |
*catalog_hash = effective_hash; |
54 |
|
18 |
return kLoadNew; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
|
58 |
|
2 |
Catalog* SimpleCatalogManager::CreateCatalog(const PathString &mountpoint, |
59 |
|
|
const shash::Any &catalog_hash, |
60 |
|
|
Catalog *parent_catalog) |
61 |
|
|
{ |
62 |
|
2 |
Catalog *new_catalog = new Catalog(mountpoint, catalog_hash, parent_catalog); |
63 |
✓✗ |
2 |
if (manage_catalog_files_) { |
64 |
|
2 |
new_catalog->TakeDatabaseFileOwnership(); |
65 |
|
|
} |
66 |
|
|
|
67 |
|
2 |
return new_catalog; |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
} // namespace catalog |