CernVM-FS  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dirtab.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_PATH_FILTERS_DIRTAB_H_
6 #define CVMFS_PATH_FILTERS_DIRTAB_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "pathspec/pathspec.h"
12 
13 namespace catalog {
14 
15 // TODO(jblomer): Dirtab and RelaxedPathFilter can use static inhertiance. It
16 // is clear at compile time which one should be used. They are not on a
17 // critical path though.
18 
51 class Dirtab {
52  public:
53  static const char kCommentMarker = '#';
54  static const char kNegationMarker = '!';
55 
61  struct Rule {
62  Rule(const Pathspec &pathspec, const bool is_negation) :
63  pathspec(pathspec), is_negation(is_negation) {}
66  };
67 
68  typedef std::vector<Rule> Rules;
69 
73  Dirtab();
74 
75  virtual ~Dirtab() {}
76 
84  static Dirtab* Create(const std::string &dirtab_path) {
85  Dirtab *dt = new Dirtab();
86  dt->Open(dirtab_path);
87  return dt;
88  }
89 
98  virtual bool Parse(const std::string &dirtab);
99  virtual bool Parse(FILE *dirtab_file);
100 
109  virtual bool IsMatching(const std::string &path) const;
110 
119  virtual bool IsOpposing(const std::string &path) const;
120 
121  const Rules& positive_rules() const { return positive_rules_; }
122  const Rules& negative_rules() const { return negative_rules_; }
123 
124  size_t RuleCount() const { return NegativeRuleCount() + PositiveRuleCount(); }
125  size_t NegativeRuleCount() const { return negative_rules_.size(); }
126  size_t PositiveRuleCount() const { return positive_rules_.size(); }
127  bool IsValid() const { return valid_; }
128 
129  protected:
133  bool Open(const std::string &dirtab_path);
134  bool ParseLine(const std::string &line);
135  virtual bool ParsePathspec(const std::string &pathspec_str, bool negation);
136  void AddRule(const Rule &rule);
137 
138  private:
140  const std::string::const_iterator &end,
141  std::string::const_iterator *itr) const
142  {
143  for (; *itr != end && **itr == ' '; ++(*itr)) { }
144  }
145  bool CheckRuleValidity() const;
146 
147  private:
148  bool valid_;
151 };
152 
153 } // namespace catalog
154 
155 #endif // CVMFS_PATH_FILTERS_DIRTAB_H_
156 
virtual bool IsMatching(const std::string &path) const
Definition: dirtab.cc:144
virtual ~Dirtab()
Definition: dirtab.h:75
bool IsValid() const
Definition: dirtab.h:127
std::vector< Rule > Rules
Definition: dirtab.h:68
bool Open(const std::string &dirtab_path)
Definition: dirtab.cc:21
Rules positive_rules_
Definition: dirtab.h:149
void SkipWhitespace(const std::string::const_iterator &end, std::string::const_iterator *itr) const
Definition: dirtab.h:139
bool ParseLine(const std::string &line)
Definition: dirtab.cc:72
const Rules & positive_rules() const
Definition: dirtab.h:121
static const char kCommentMarker
Definition: dirtab.h:53
size_t PositiveRuleCount() const
Definition: dirtab.h:126
virtual bool IsOpposing(const std::string &path) const
Definition: dirtab.cc:161
Rule(const Pathspec &pathspec, const bool is_negation)
Definition: dirtab.h:62
static Dirtab * Create(const std::string &dirtab_path)
Definition: dirtab.h:84
virtual bool ParsePathspec(const std::string &pathspec_str, bool negation)
Definition: dirtab.cc:95
void AddRule(const Rule &rule)
Definition: dirtab.cc:115
size_t NegativeRuleCount() const
Definition: dirtab.h:125
size_t RuleCount() const
Definition: dirtab.h:124
Rules negative_rules_
Definition: dirtab.h:150
Pathspec pathspec
Definition: dirtab.h:64
virtual bool Parse(const std::string &dirtab)
Definition: dirtab.cc:43
const Rules & negative_rules() const
Definition: dirtab.h:122
bool CheckRuleValidity() const
Definition: dirtab.cc:124
static const char kNegationMarker
Definition: dirtab.h:54