CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
relaxed_path_filter.cc
Go to the documentation of this file.
1 
5 #include <cstdio>
6 #include <string>
7 
9 
10 using namespace catalog; // NOLINT
11 
12 RelaxedPathFilter *RelaxedPathFilter::Create(const std::string &dirtab_path) {
14  dt->Open(dirtab_path);
15  return dt;
16 }
17 
18 
19 bool RelaxedPathFilter::IsMatching(const std::string &path) const {
20  bool has_positive_match = Dirtab::IsMatching(path);
21  if (!has_positive_match) {
22  std::string current_path = path;
23  while (current_path.length() > 0) {
24  size_t new_length = current_path.find_last_of("/");
25  current_path = current_path.substr(0, new_length);
26  if (exact_dirtab_.IsMatching(current_path)) {
27  has_positive_match = true;
28  break;
29  }
30  } // walk through sub paths
31  }
32 
33  return has_positive_match && !IsOpposing(path);
34 }
35 
36 
37 bool RelaxedPathFilter::IsOpposing(const std::string &path) const {
38  if (Dirtab::IsOpposing(path))
39  return true;
40 
41  std::string current_path = path;
42  while (current_path.length() > 0) {
43  size_t new_length = current_path.find_last_of("/");
44  current_path = current_path.substr(0, new_length);
45  if (Dirtab::IsOpposing(current_path)) {
46  return true;
47  }
48  }
49 
50  return false;
51 }
52 
53 
54 bool RelaxedPathFilter::Parse(const std::string &dirtab) {
55  return Dirtab::Parse(dirtab) & exact_dirtab_.Parse(dirtab);
56 }
57 
58 bool RelaxedPathFilter::Parse(FILE *dirtab_file) {
59  bool result = Dirtab::Parse(dirtab_file);
60  rewind(dirtab_file);
61  result &= exact_dirtab_.Parse(dirtab_file);
62  return result;
63 }
64 
65 
66 bool RelaxedPathFilter::ParsePathspec(const std::string &pathspec_str,
67  bool negation) {
68  if (negation) {
69  return Dirtab::ParsePathspec(pathspec_str, true);
70  }
71  bool success = true;
72  std::string current_pathspec_str(pathspec_str);
73  while (current_pathspec_str.length() > 0) {
74  if (!Dirtab::ParsePathspec(current_pathspec_str, false))
75  success = false;
76  size_t new_length = current_pathspec_str.find_last_of("/");
77  current_pathspec_str = current_pathspec_str.substr(0, new_length);
78  }
79 
80  return success;
81 }
static RelaxedPathFilter * Create(const std::string &dirtab_path)
virtual bool IsMatching(const std::string &path) const
Definition: dirtab.cc:144
bool Open(const std::string &dirtab_path)
Definition: dirtab.cc:21
virtual bool Parse(const std::string &dirtab)
virtual bool IsOpposing(const std::string &path) const
Definition: dirtab.cc:161
virtual bool IsMatching(const std::string &path) const
virtual bool ParsePathspec(const std::string &pathspec_str, bool negation)
Definition: dirtab.cc:95
virtual bool ParsePathspec(const std::string &pathspec_str, bool negation)
virtual bool IsOpposing(const std::string &path) const
virtual bool Parse(const std::string &dirtab)
Definition: dirtab.cc:43