GCC Code Coverage Report
Directory: cvmfs/ Exec Total Coverage
File: cvmfs/path_filters/relaxed_path_filter.cc Lines: 43 44 97.7 %
Date: 2019-02-03 02:48:13 Branches: 21 22 95.5 %

Line Branch Exec Source
1
/**
2
 * This file is part of the CernVM File System.
3
 */
4
5
#include <cstdio>
6
#include <string>
7
8
#include "path_filters/relaxed_path_filter.h"
9
10
using namespace catalog;  // NOLINT
11
12
1
RelaxedPathFilter *RelaxedPathFilter::Create(const std::string &dirtab_path) {
13
1
  RelaxedPathFilter *dt = new RelaxedPathFilter();
14
1
  dt->Open(dirtab_path);
15
1
  return dt;
16
}
17
18
19
26
bool RelaxedPathFilter::IsMatching(const std::string &path) const {
20
26
  bool has_positive_match = Dirtab::IsMatching(path);
21
26
  if (!has_positive_match) {
22
16
    std::string current_path = path;
23
16
    while (current_path.length() > 0) {
24
23
      size_t new_length = current_path.find_last_of("/");
25
23
      current_path = current_path.substr(0, new_length);
26
23
      if (exact_dirtab_.IsMatching(current_path)) {
27
10
        has_positive_match = true;
28
10
        break;
29
      }
30
16
    }  // walk through sub paths
31
  }
32
33

26
  return has_positive_match && !IsOpposing(path);
34
}
35
36
37
33
bool RelaxedPathFilter::IsOpposing(const std::string &path) const {
38
33
  if (Dirtab::IsOpposing(path))
39
4
    return true;
40
41
29
  std::string current_path = path;
42
29
  while (current_path.length() > 0) {
43
64
    size_t new_length = current_path.find_last_of("/");
44
64
    current_path = current_path.substr(0, new_length);
45
64
    if (Dirtab::IsOpposing(current_path)) {
46
2
      return true;
47
    }
48
  }
49
50
27
  return false;
51
}
52
53
54
3
bool RelaxedPathFilter::Parse(const std::string &dirtab) {
55
3
  return Dirtab::Parse(dirtab) & exact_dirtab_.Parse(dirtab);
56
}
57
58
1
bool RelaxedPathFilter::Parse(FILE *dirtab_file) {
59
1
  bool result = Dirtab::Parse(dirtab_file);
60
1
  rewind(dirtab_file);
61
1
  result &= exact_dirtab_.Parse(dirtab_file);
62
1
  return result;
63
}
64
65
66
11
bool RelaxedPathFilter::ParsePathspec(const std::string &pathspec_str,
67
                                      bool negation) {
68
11
  if (negation) {
69
5
    return Dirtab::ParsePathspec(pathspec_str, true);
70
  }
71
6
  bool success = true;
72
6
  std::string current_pathspec_str(pathspec_str);
73
28
  while (current_pathspec_str.length() > 0) {
74
16
    if (!Dirtab::ParsePathspec(current_pathspec_str, false))
75
      success = false;
76
16
    size_t new_length = current_pathspec_str.find_last_of("/");
77
16
    current_pathspec_str = current_pathspec_str.substr(0, new_length);
78
  }
79
80
6
  return success;
81
}