| Directory: | cvmfs/ |
|---|---|
| File: | cvmfs/upload_spooler_definition.cc |
| Date: | 2025-11-09 02:35:23 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 32 | 44 | 72.7% |
| Branches: | 18 | 35 | 51.4% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | * This file is part of the CernVM File System. | ||
| 3 | */ | ||
| 4 | |||
| 5 | #include "upload_spooler_definition.h" | ||
| 6 | |||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "util/logging.h" | ||
| 10 | #include "util/string.h" | ||
| 11 | |||
| 12 | namespace upload { | ||
| 13 | |||
| 14 | const char *SpoolerDefinition::kDriverNames[] = {"S3", "local", "gw", "mock", | ||
| 15 | "unknown"}; | ||
| 16 | |||
| 17 | 3696 | SpoolerDefinition::SpoolerDefinition( | |
| 18 | const std::string &definition_string, | ||
| 19 | const shash::Algorithms hash_algorithm, | ||
| 20 | const zlib::Algorithms compression_algorithm, | ||
| 21 | const bool generate_legacy_bulk_chunks, | ||
| 22 | const bool use_file_chunking, | ||
| 23 | const size_t min_file_chunk_size, | ||
| 24 | const size_t avg_file_chunk_size, | ||
| 25 | const size_t max_file_chunk_size, | ||
| 26 | const std::string &session_token_file, | ||
| 27 | 3696 | const std::string &key_file) | |
| 28 | 3696 | : driver_type(Unknown) | |
| 29 | 3696 | , hash_algorithm(hash_algorithm) | |
| 30 | 3696 | , compression_alg(compression_algorithm) | |
| 31 | 3696 | , generate_legacy_bulk_chunks(generate_legacy_bulk_chunks) | |
| 32 | 3696 | , use_file_chunking(use_file_chunking) | |
| 33 | 3696 | , min_file_chunk_size(min_file_chunk_size) | |
| 34 | 3696 | , avg_file_chunk_size(avg_file_chunk_size) | |
| 35 | 3696 | , max_file_chunk_size(max_file_chunk_size) | |
| 36 | 3696 | , number_of_concurrent_uploads(kDefaultMaxConcurrentUploads) | |
| 37 | 3696 | , num_upload_tasks(kDefaultNumUploadTasks) | |
| 38 |
1/2✓ Branch 1 taken 3696 times.
✗ Branch 2 not taken.
|
3696 | , session_token_file(session_token_file) |
| 39 |
1/2✓ Branch 1 taken 3696 times.
✗ Branch 2 not taken.
|
3696 | , key_file(key_file) |
| 40 | 3696 | , valid_(false) { | |
| 41 | // check if given file chunking values are sane | ||
| 42 |
2/2✓ Branch 0 taken 3592 times.
✓ Branch 1 taken 104 times.
|
3696 | if (use_file_chunking |
| 43 |
1/2✓ Branch 0 taken 3592 times.
✗ Branch 1 not taken.
|
3592 | && (min_file_chunk_size >= avg_file_chunk_size |
| 44 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3592 times.
|
3592 | || avg_file_chunk_size >= max_file_chunk_size)) { |
| 45 | ✗ | LogCvmfs(kLogSpooler, kLogStderr, "file chunk size values are not sane"); | |
| 46 | ✗ | return; | |
| 47 | } | ||
| 48 | |||
| 49 | // split the spooler driver definition into name and config part | ||
| 50 |
1/2✓ Branch 1 taken 3696 times.
✗ Branch 2 not taken.
|
3696 | std::vector<std::string> upstream = SplitString(definition_string, ','); |
| 51 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3696 times.
|
3696 | if (upstream.size() != 3) { |
| 52 | ✗ | LogCvmfs(kLogSpooler, kLogStderr, "Invalid spooler driver"); | |
| 53 | ✗ | return; | |
| 54 | } | ||
| 55 | |||
| 56 | // recognize and configure the spooler driver | ||
| 57 |
2/2✓ Branch 2 taken 1270 times.
✓ Branch 3 taken 2426 times.
|
3696 | if (upstream[0] == "local") { |
| 58 | 1270 | driver_type = Local; | |
| 59 |
2/2✓ Branch 2 taken 264 times.
✓ Branch 3 taken 2162 times.
|
2426 | } else if (upstream[0] == "S3") { |
| 60 | 264 | driver_type = S3; | |
| 61 |
2/2✓ Branch 2 taken 104 times.
✓ Branch 3 taken 2058 times.
|
2162 | } else if (upstream[0] == "gw") { |
| 62 | 104 | driver_type = Gateway; | |
| 63 |
1/2✓ Branch 2 taken 2058 times.
✗ Branch 3 not taken.
|
2058 | } else if (upstream[0] == "mock") { |
| 64 | 2058 | driver_type = Mock; // for unit testing purpose only! | |
| 65 | } else { | ||
| 66 | ✗ | driver_type = Unknown; | |
| 67 | ✗ | LogCvmfs(kLogSpooler, kLogStderr, "unknown spooler driver: %s", | |
| 68 | ✗ | upstream[0].c_str()); | |
| 69 | ✗ | return; | |
| 70 | } | ||
| 71 | |||
| 72 | // save data | ||
| 73 |
1/2✓ Branch 2 taken 3696 times.
✗ Branch 3 not taken.
|
3696 | temporary_path = upstream[1]; |
| 74 |
1/2✓ Branch 2 taken 3696 times.
✗ Branch 3 not taken.
|
3696 | spooler_configuration = upstream[2]; |
| 75 | 3696 | valid_ = true; | |
| 76 |
1/2✓ Branch 1 taken 3696 times.
✗ Branch 2 not taken.
|
3696 | } |
| 77 | |||
| 78 | ✗ | SpoolerDefinition SpoolerDefinition::Dup2DefaultCompression() const { | |
| 79 | ✗ | SpoolerDefinition result(*this); | |
| 80 | ✗ | result.compression_alg = zlib::kZlibDefault; | |
| 81 | ✗ | return result; | |
| 82 | } | ||
| 83 | |||
| 84 | } // namespace upload | ||
| 85 |