Directory: | cvmfs/ |
---|---|
File: | cvmfs/catalog_mgr_ro.cc |
Date: | 2024-04-28 02:33:07 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 28 | 29 | 96.6% |
Branches: | 17 | 32 | 53.1% |
Line | Branch | Exec | Source |
---|---|---|---|
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 "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 | 31 | LoadReturn SimpleCatalogManager::GetNewRootCatalogContext( | |
19 | CatalogContext *result) { | ||
20 |
1/2✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
|
31 | if (result->hash().IsNull()) { |
21 | 31 | result->SetHash(base_hash_); | |
22 | } | ||
23 | 31 | result->SetRootCtlgLocation(kCtlgLocationServer); | |
24 |
1/2✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
|
31 | result->SetMountpoint(PathString("", 0)); |
25 | |||
26 | 31 | return kLoadNew; | |
27 | } | ||
28 | |||
29 | |||
30 | /** | ||
31 | * Loads a catalog via HTTP from Statum 0 into a temporary file. | ||
32 | * See CatalogContext class description for correct usage | ||
33 | * | ||
34 | * @return kLoadNew on success | ||
35 | */ | ||
36 | 50 | LoadReturn SimpleCatalogManager::LoadCatalogByHash( | |
37 | CatalogContext *ctlg_context) { | ||
38 | 50 | const shash::Any effective_hash = ctlg_context->hash(); | |
39 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
|
50 | assert(shash::kSuffixCatalog == effective_hash.suffix); |
40 |
3/6✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 50 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 50 times.
✗ Branch 8 not taken.
|
100 | const string url = stratum0_ + "/data/" + effective_hash.MakePath(); |
41 | |||
42 | 50 | std::string tmp; | |
43 | |||
44 |
2/4✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 50 times.
✗ Branch 5 not taken.
|
50 | FILE *fcatalog = CreateTempFile(dir_temp_ + "/catalog", 0666, "w", &tmp); |
45 |
1/2✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
|
50 | ctlg_context->SetSqlitePath(tmp); |
46 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
|
50 | if (!fcatalog) { |
47 | ✗ | PANIC(kLogStderr, "failed to create temp file when loading %s", | |
48 | url.c_str()); | ||
49 | } | ||
50 | |||
51 | 50 | cvmfs::FileSink filesink(fcatalog); | |
52 | download::JobInfo download_catalog(&url, true, false, | ||
53 |
1/2✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
|
50 | &effective_hash, &filesink); |
54 |
1/2✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
|
50 | const download::Failures retval = download_manager_->Fetch(&download_catalog); |
55 |
1/2✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
|
50 | fclose(fcatalog); |
56 | |||
57 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 49 times.
|
50 | if (retval != download::kFailOk) { |
58 | 1 | unlink(ctlg_context->GetSqlitePathPtr()->c_str()); | |
59 | 1 | PANIC(kLogStderr, "failed to load %s from Stratum 0 (%d - %s)", | |
60 | url.c_str(), retval, download::Code2Ascii(retval)); | ||
61 | } | ||
62 | |||
63 | 49 | return kLoadNew; | |
64 | 53 | } | |
65 | |||
66 | |||
67 | 5 | Catalog* SimpleCatalogManager::CreateCatalog(const PathString &mountpoint, | |
68 | const shash::Any &catalog_hash, | ||
69 | Catalog *parent_catalog) | ||
70 | { | ||
71 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | Catalog *new_catalog = new Catalog(mountpoint, catalog_hash, parent_catalog); |
72 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (manage_catalog_files_) { |
73 | 5 | new_catalog->TakeDatabaseFileOwnership(); | |
74 | } | ||
75 | |||
76 | 5 | return new_catalog; | |
77 | } | ||
78 | |||
79 | } // namespace catalog | ||
80 |