GCC Code Coverage Report
Directory: cvmfs/ Exec Total Coverage
File: cvmfs/upload_spooler_definition.cc Lines: 16 25 64.0 %
Date: 2019-02-03 02:48:13 Branches: 12 16 75.0 %

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 "logging.h"
10
#include "util/string.h"
11
12
namespace upload {
13
14
299
SpoolerDefinition::SpoolerDefinition(
15
    const std::string& definition_string,
16
    const shash::Algorithms hash_algorithm,
17
    const zlib::Algorithms compression_algorithm,
18
    const bool generate_legacy_bulk_chunks,
19
    const bool use_file_chunking,
20
    const size_t min_file_chunk_size,
21
    const size_t avg_file_chunk_size,
22
    const size_t max_file_chunk_size,
23
    const std::string& session_token_file,
24
    const std::string& key_file)
25
    : driver_type(Unknown),
26
      hash_algorithm(hash_algorithm),
27
      compression_alg(compression_algorithm),
28
      generate_legacy_bulk_chunks(generate_legacy_bulk_chunks),
29
      use_file_chunking(use_file_chunking),
30
      min_file_chunk_size(min_file_chunk_size),
31
      avg_file_chunk_size(avg_file_chunk_size),
32
      max_file_chunk_size(max_file_chunk_size),
33
      number_of_concurrent_uploads(kDefaultMaxConcurrentUploads),
34
      num_upload_tasks(kDefaultNumUploadTasks),
35
      session_token_file(session_token_file),
36
      key_file(key_file),
37
299
      valid_(false) {
38
  // check if given file chunking values are sane
39

299
  if (use_file_chunking && (min_file_chunk_size >= avg_file_chunk_size ||
40
                            avg_file_chunk_size >= max_file_chunk_size)) {
41
    LogCvmfs(kLogSpooler, kLogStderr, "file chunk size values are not sane");
42
    return;
43
  }
44
45
  // split the spooler driver definition into name and config part
46
299
  std::vector<std::string> upstream = SplitString(definition_string, ',');
47
299
  if (upstream.size() != 3) {
48
    LogCvmfs(kLogSpooler, kLogStderr, "Invalid spooler driver");
49
    return;
50
  }
51
52
  // recognize and configure the spooler driver
53
299
  if (upstream[0] == "local") {
54
32
    driver_type = Local;
55
267
  } else if (upstream[0] == "S3") {
56
99
    driver_type = S3;
57
168
  } else if (upstream[0] == "gw") {
58
7
    driver_type = Gateway;
59
161
  } else if (upstream[0] == "mock") {
60
161
    driver_type = Mock;  // for unit testing purpose only!
61
  } else {
62
    driver_type = Unknown;
63
    LogCvmfs(kLogSpooler, kLogStderr, "unknown spooler driver: %s",
64
             upstream[0].c_str());
65
    return;
66
  }
67
68
  // save data
69
299
  temporary_path = upstream[1];
70
299
  spooler_configuration = upstream[2];
71
299
  valid_ = true;
72
}
73
74
SpoolerDefinition SpoolerDefinition::Dup2DefaultCompression() const {
75
  SpoolerDefinition result(*this);
76
  result.compression_alg = zlib::kZlibDefault;
77
  return result;
78
}
79
80
}  // namespace upload