GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/path_filters/relaxed_path_filter.cc
Date: 2026-02-15 02:35:50
Exec Total Coverage
Lines: 45 46 97.8%
Branches: 33 46 71.7%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5 #include "path_filters/relaxed_path_filter.h"
6
7 #include <cstdio>
8 #include <string>
9
10 using namespace catalog; // NOLINT
11
12 20 RelaxedPathFilter *RelaxedPathFilter::Create(const std::string &dirtab_path) {
13
1/2
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
20 RelaxedPathFilter *dt = new RelaxedPathFilter();
14 20 dt->Open(dirtab_path);
15 20 return dt;
16 }
17
18
19 520 bool RelaxedPathFilter::IsMatching(const std::string &path) const {
20 520 bool has_positive_match = Dirtab::IsMatching(path);
21
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 200 times.
520 if (!has_positive_match) {
22
1/2
✓ Branch 1 taken 320 times.
✗ Branch 2 not taken.
320 std::string current_path = path;
23
2/2
✓ Branch 1 taken 460 times.
✓ Branch 2 taken 120 times.
580 while (current_path.length() > 0) {
24 460 const size_t new_length = current_path.find_last_of("/");
25
1/2
✓ Branch 1 taken 460 times.
✗ Branch 2 not taken.
460 current_path = current_path.substr(0, new_length);
26
3/4
✓ Branch 1 taken 460 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 200 times.
✓ Branch 4 taken 260 times.
460 if (exact_dirtab_.IsMatching(current_path)) {
27 200 has_positive_match = true;
28 200 break;
29 }
30 } // walk through sub paths
31 320 }
32
33
4/4
✓ Branch 0 taken 400 times.
✓ Branch 1 taken 120 times.
✓ Branch 3 taken 300 times.
✓ Branch 4 taken 100 times.
520 return has_positive_match && !IsOpposing(path);
34 }
35
36
37 660 bool RelaxedPathFilter::IsOpposing(const std::string &path) const {
38
3/4
✓ Branch 1 taken 660 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 80 times.
✓ Branch 4 taken 580 times.
660 if (Dirtab::IsOpposing(path))
39 80 return true;
40
41
1/2
✓ Branch 1 taken 580 times.
✗ Branch 2 not taken.
580 std::string current_path = path;
42
2/2
✓ Branch 1 taken 1280 times.
✓ Branch 2 taken 540 times.
1820 while (current_path.length() > 0) {
43 1280 const size_t new_length = current_path.find_last_of("/");
44
1/2
✓ Branch 1 taken 1280 times.
✗ Branch 2 not taken.
1280 current_path = current_path.substr(0, new_length);
45
3/4
✓ Branch 1 taken 1280 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 40 times.
✓ Branch 4 taken 1240 times.
1280 if (Dirtab::IsOpposing(current_path)) {
46 40 return true;
47 }
48 }
49
50 540 return false;
51 580 }
52
53
54 60 bool RelaxedPathFilter::Parse(const std::string &dirtab) {
55 60 return Dirtab::Parse(dirtab) & exact_dirtab_.Parse(dirtab);
56 }
57
58 20 bool RelaxedPathFilter::Parse(FILE *dirtab_file) {
59 20 bool result = Dirtab::Parse(dirtab_file);
60 20 rewind(dirtab_file);
61 20 result &= exact_dirtab_.Parse(dirtab_file);
62 20 return result;
63 }
64
65
66 220 bool RelaxedPathFilter::ParsePathspec(const std::string &pathspec_str,
67 bool negation) {
68
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 120 times.
220 if (negation) {
69
1/2
✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
100 return Dirtab::ParsePathspec(pathspec_str, true);
70 }
71 120 bool success = true;
72
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 std::string current_pathspec_str(pathspec_str);
73
2/2
✓ Branch 1 taken 320 times.
✓ Branch 2 taken 120 times.
440 while (current_pathspec_str.length() > 0) {
74
2/4
✓ Branch 1 taken 320 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 320 times.
320 if (!Dirtab::ParsePathspec(current_pathspec_str, false))
75 success = false;
76 320 const size_t new_length = current_pathspec_str.find_last_of("/");
77
1/2
✓ Branch 1 taken 320 times.
✗ Branch 2 not taken.
320 current_pathspec_str = current_pathspec_str.substr(0, new_length);
78 }
79
80 120 return success;
81 120 }
82