GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/path_filters/relaxed_path_filter.cc
Date: 2026-10-25 02:40:14
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 49 RelaxedPathFilter *RelaxedPathFilter::Create(const std::string &dirtab_path) {
13
1/2
✓ Branch 2 taken 49 times.
✗ Branch 3 not taken.
49 RelaxedPathFilter *dt = new RelaxedPathFilter();
14 49 dt->Open(dirtab_path);
15 49 return dt;
16 }
17
18
19 6206 bool RelaxedPathFilter::IsMatching(const std::string &path) const {
20 6206 bool has_positive_match = Dirtab::IsMatching(path);
21
2/2
✓ Branch 0 taken 3496 times.
✓ Branch 1 taken 2710 times.
6206 if (!has_positive_match) {
22
1/2
✓ Branch 1 taken 3496 times.
✗ Branch 2 not taken.
3496 std::string current_path = path;
23
2/2
✓ Branch 1 taken 5759 times.
✓ Branch 2 taken 1974 times.
7733 while (current_path.length() > 0) {
24 5759 const size_t new_length = current_path.find_last_of("/");
25
1/2
✓ Branch 1 taken 5759 times.
✗ Branch 2 not taken.
5759 current_path = current_path.substr(0, new_length);
26
3/4
✓ Branch 1 taken 5759 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1522 times.
✓ Branch 4 taken 4237 times.
5759 if (exact_dirtab_.IsMatching(current_path)) {
27 1522 has_positive_match = true;
28 1522 break;
29 }
30 } // walk through sub paths
31 3496 }
32
33
4/4
✓ Branch 0 taken 4232 times.
✓ Branch 1 taken 1974 times.
✓ Branch 3 taken 3659 times.
✓ Branch 4 taken 573 times.
6206 return has_positive_match && !IsOpposing(path);
34 }
35
36
37 7089 bool RelaxedPathFilter::IsOpposing(const std::string &path) const {
38
3/4
✓ Branch 1 taken 7089 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 476 times.
✓ Branch 4 taken 6613 times.
7089 if (Dirtab::IsOpposing(path))
39 476 return true;
40
41
1/2
✓ Branch 1 taken 6613 times.
✗ Branch 2 not taken.
6613 std::string current_path = path;
42
2/2
✓ Branch 1 taken 14992 times.
✓ Branch 2 taken 6467 times.
21459 while (current_path.length() > 0) {
43 14992 const size_t new_length = current_path.find_last_of("/");
44
1/2
✓ Branch 1 taken 14992 times.
✗ Branch 2 not taken.
14992 current_path = current_path.substr(0, new_length);
45
3/4
✓ Branch 1 taken 14992 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 146 times.
✓ Branch 4 taken 14846 times.
14992 if (Dirtab::IsOpposing(current_path)) {
46 146 return true;
47 }
48 }
49
50 6467 return false;
51 6613 }
52
53
54 753 bool RelaxedPathFilter::Parse(const std::string &dirtab) {
55 753 return Dirtab::Parse(dirtab) & exact_dirtab_.Parse(dirtab);
56 }
57
58 49 bool RelaxedPathFilter::Parse(FILE *dirtab_file) {
59 49 bool result = Dirtab::Parse(dirtab_file);
60 49 rewind(dirtab_file);
61 49 result &= exact_dirtab_.Parse(dirtab_file);
62 49 return result;
63 }
64
65
66 1857 bool RelaxedPathFilter::ParsePathspec(const std::string &pathspec_str,
67 bool negation) {
68
2/2
✓ Branch 0 taken 351 times.
✓ Branch 1 taken 1506 times.
1857 if (negation) {
69
1/2
✓ Branch 1 taken 351 times.
✗ Branch 2 not taken.
351 return Dirtab::ParsePathspec(pathspec_str, true);
70 }
71 1506 bool success = true;
72
1/2
✓ Branch 1 taken 1506 times.
✗ Branch 2 not taken.
1506 std::string current_pathspec_str(pathspec_str);
73
2/2
✓ Branch 1 taken 2332 times.
✓ Branch 2 taken 1506 times.
3838 while (current_pathspec_str.length() > 0) {
74
2/4
✓ Branch 1 taken 2332 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 2332 times.
2332 if (!Dirtab::ParsePathspec(current_pathspec_str, false))
75 ✗ success = false;
76 2332 const size_t new_length = current_pathspec_str.find_last_of("/");
77
1/2
✓ Branch 1 taken 2332 times.
✗ Branch 2 not taken.
2332 current_pathspec_str = current_pathspec_str.substr(0, new_length);
78 }
79
80 1506 return success;
81 1506 }
82