| Directory: | cvmfs/ |
|---|---|
| File: | cvmfs/path_filters/relaxed_path_filter.cc |
| Date: | 2025-12-14 02:35:46 |
| 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 | 45 | RelaxedPathFilter *RelaxedPathFilter::Create(const std::string &dirtab_path) { | |
| 13 |
1/2✓ Branch 2 taken 45 times.
✗ Branch 3 not taken.
|
45 | RelaxedPathFilter *dt = new RelaxedPathFilter(); |
| 14 | 45 | dt->Open(dirtab_path); | |
| 15 | 45 | return dt; | |
| 16 | } | ||
| 17 | |||
| 18 | |||
| 19 | 1170 | bool RelaxedPathFilter::IsMatching(const std::string &path) const { | |
| 20 | 1170 | bool has_positive_match = Dirtab::IsMatching(path); | |
| 21 |
2/2✓ Branch 0 taken 720 times.
✓ Branch 1 taken 450 times.
|
1170 | if (!has_positive_match) { |
| 22 |
1/2✓ Branch 1 taken 720 times.
✗ Branch 2 not taken.
|
720 | std::string current_path = path; |
| 23 |
2/2✓ Branch 1 taken 1035 times.
✓ Branch 2 taken 270 times.
|
1305 | while (current_path.length() > 0) { |
| 24 | 1035 | const size_t new_length = current_path.find_last_of("/"); | |
| 25 |
1/2✓ Branch 1 taken 1035 times.
✗ Branch 2 not taken.
|
1035 | current_path = current_path.substr(0, new_length); |
| 26 |
3/4✓ Branch 1 taken 1035 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 450 times.
✓ Branch 4 taken 585 times.
|
1035 | if (exact_dirtab_.IsMatching(current_path)) { |
| 27 | 450 | has_positive_match = true; | |
| 28 | 450 | break; | |
| 29 | } | ||
| 30 | } // walk through sub paths | ||
| 31 | 720 | } | |
| 32 | |||
| 33 |
4/4✓ Branch 0 taken 900 times.
✓ Branch 1 taken 270 times.
✓ Branch 3 taken 675 times.
✓ Branch 4 taken 225 times.
|
1170 | return has_positive_match && !IsOpposing(path); |
| 34 | } | ||
| 35 | |||
| 36 | |||
| 37 | 1485 | bool RelaxedPathFilter::IsOpposing(const std::string &path) const { | |
| 38 |
3/4✓ Branch 1 taken 1485 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 180 times.
✓ Branch 4 taken 1305 times.
|
1485 | if (Dirtab::IsOpposing(path)) |
| 39 | 180 | return true; | |
| 40 | |||
| 41 |
1/2✓ Branch 1 taken 1305 times.
✗ Branch 2 not taken.
|
1305 | std::string current_path = path; |
| 42 |
2/2✓ Branch 1 taken 2880 times.
✓ Branch 2 taken 1215 times.
|
4095 | while (current_path.length() > 0) { |
| 43 | 2880 | const size_t new_length = current_path.find_last_of("/"); | |
| 44 |
1/2✓ Branch 1 taken 2880 times.
✗ Branch 2 not taken.
|
2880 | current_path = current_path.substr(0, new_length); |
| 45 |
3/4✓ Branch 1 taken 2880 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 90 times.
✓ Branch 4 taken 2790 times.
|
2880 | if (Dirtab::IsOpposing(current_path)) { |
| 46 | 90 | return true; | |
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | 1215 | return false; | |
| 51 | 1305 | } | |
| 52 | |||
| 53 | |||
| 54 | 135 | bool RelaxedPathFilter::Parse(const std::string &dirtab) { | |
| 55 | 135 | return Dirtab::Parse(dirtab) & exact_dirtab_.Parse(dirtab); | |
| 56 | } | ||
| 57 | |||
| 58 | 45 | bool RelaxedPathFilter::Parse(FILE *dirtab_file) { | |
| 59 | 45 | bool result = Dirtab::Parse(dirtab_file); | |
| 60 | 45 | rewind(dirtab_file); | |
| 61 | 45 | result &= exact_dirtab_.Parse(dirtab_file); | |
| 62 | 45 | return result; | |
| 63 | } | ||
| 64 | |||
| 65 | |||
| 66 | 495 | bool RelaxedPathFilter::ParsePathspec(const std::string &pathspec_str, | |
| 67 | bool negation) { | ||
| 68 |
2/2✓ Branch 0 taken 225 times.
✓ Branch 1 taken 270 times.
|
495 | if (negation) { |
| 69 |
1/2✓ Branch 1 taken 225 times.
✗ Branch 2 not taken.
|
225 | return Dirtab::ParsePathspec(pathspec_str, true); |
| 70 | } | ||
| 71 | 270 | bool success = true; | |
| 72 |
1/2✓ Branch 1 taken 270 times.
✗ Branch 2 not taken.
|
270 | std::string current_pathspec_str(pathspec_str); |
| 73 |
2/2✓ Branch 1 taken 720 times.
✓ Branch 2 taken 270 times.
|
990 | while (current_pathspec_str.length() > 0) { |
| 74 |
2/4✓ Branch 1 taken 720 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 720 times.
|
720 | if (!Dirtab::ParsePathspec(current_pathspec_str, false)) |
| 75 | ✗ | success = false; | |
| 76 | 720 | const size_t new_length = current_pathspec_str.find_last_of("/"); | |
| 77 |
1/2✓ Branch 1 taken 720 times.
✗ Branch 2 not taken.
|
720 | current_pathspec_str = current_pathspec_str.substr(0, new_length); |
| 78 | } | ||
| 79 | |||
| 80 | 270 | return success; | |
| 81 | 270 | } | |
| 82 |