CernVM-FS
2.12.0
|
#include <pathspec.h>
Public Types | |
typedef std::vector< std::string > | GlobStringSequence |
Public Member Functions | |
Pathspec (const std::string &spec) | |
Pathspec (const Pathspec &other) | |
~Pathspec () | |
bool | IsMatching (const std::string &query_path) const |
bool | IsPrefixMatching (const std::string &query_path) const |
bool | IsMatchingRelaxed (const std::string &query_path) const |
bool | IsValid () const |
bool | IsAbsolute () const |
const GlobStringSequence & | GetGlobStringSequence () const |
const std::string & | GetGlobString () const |
Pathspec & | operator= (const Pathspec &other) |
bool | operator== (const Pathspec &other) const |
bool | operator!= (const Pathspec &other) const |
Static Public Member Functions | |
static bool | IsSpecialChar (const char chr) |
Static Public Attributes | |
static const char | kSeparator = '/' |
static const char | kEscaper = '\\' |
static const char | kWildcard = '*' |
static const char | kPlaceholder = '?' |
Protected Types | |
typedef std::vector < PathspecElementPattern > | ElementPatterns |
Protected Member Functions | |
void | Parse (const std::string &spec) |
void | ParsePathElement (const std::string::const_iterator &end, std::string::const_iterator *itr) |
bool | IsPathspecMatching (const std::string &query_path) const |
bool | IsPathspecPrefixMatching (const std::string &query_path) const |
bool | IsPathspecMatchingRelaxed (const std::string &query_path) const |
bool | ApplyRegularExpression (const std::string &query_path, regex_t *regex) const |
regex_t * | GetRegularExpression () const |
regex_t * | GetPrefixRegularExpression () const |
regex_t * | GetRelaxedRegularExpression () const |
std::string | GenerateRegularExpression (const bool is_relaxed=false, const bool is_prefix=false) const |
regex_t * | CompileRegularExpression (const std::string ®ex) const |
void | PrintRegularExpressionError (const int error_code) const |
void | GenerateGlobStringSequence () const |
void | GenerateGlobString () const |
void | DestroyRegularExpressions () |
Private Attributes | |
ElementPatterns | patterns_ |
regex_t * | regex_ |
regex_t * | relaxed_regex_ |
regex_t * | prefix_regex_ |
std::string | glob_string_ |
GlobStringSequence | glob_string_sequence_ |
bool | regex_compiled_ |
bool | relaxed_regex_compiled_ |
bool | prefix_regex_compiled_ |
bool | glob_string_compiled_ |
bool | glob_string_sequence_compiled_ |
bool | valid_ |
bool | absolute_ |
This file is part of the CernVM File System. A Pathspec is an abstract description of a file path pattern. Examples (adding a space in front of * - silence compiler warning): /foo/bar/ *.txt - matches .txt files in /foo/bar /kernel/2.6.? - matches directories like: /kernel/2.6.[0-9a-z] /test/ *_debug/ * - matches all files in /test/cvmfs_debug/ for example
We are supporting both the wildcard (i.e. *) and the placeholder (i.e. ?) symbol. Furthermore Pathspecs can be absolute (starting with /) or relative.
Pathspecs are similar to unix glob strings for file system paths and can be transforms into such strings or sequences of these (cut at directory boundaries). This comes in handy when searching CVMFS catalog entries with a Pathspec. Note: sophisticated Pathspec based catalog lookup was not needed, yet. But it is implemented and not merged (see: reneme/feature-lookup_pathspec).
Also inverse matches are possible by transforming a Pathspec into a regular expression and matching path strings with it. There are two matching modes: IsMatching() - Matches the exact path (wildcards don't span directory boundaries) IsMatchingRelaxed() - Matches the path more relaxed (comparable to shell pattern matching, wildcards match any character including /)
Internally a Pathspec is broken up into PathspecElementPatterns at the directory boundaries. Have a look there for further details.
For matching, Pathspecs need to be transformed either into a regular expres- sion or GlobString(Sequence). These transformations are done lazily on first request.
Definition at line 47 of file pathspec.h.
|
protected |
Definition at line 55 of file pathspec.h.
typedef std::vector<std::string> Pathspec::GlobStringSequence |
Definition at line 58 of file pathspec.h.
|
explicit |
Create a new Pathspec that represents the pattern handed in as a parameter. Note: The parser will determine if the given pattern is valid and set a flag. After creating a Pathspec it should be checked if .IsValid()
spec | the pathspec pattern to be parsed |
This file is part of the CernVM File System.
Definition at line 12 of file pathspec.cc.
Pathspec::Pathspec | ( | const Pathspec & | other | ) |
Definition at line 40 of file pathspec.cc.
Pathspec::~Pathspec | ( | ) |
|
protected |
Definition at line 156 of file pathspec.cc.
Referenced by IsPathspecMatching(), IsPathspecMatchingRelaxed(), and IsPathspecPrefixMatching().
|
protected |
Definition at line 245 of file pathspec.cc.
Referenced by GetPrefixRegularExpression(), GetRegularExpression(), and GetRelaxedRegularExpression().
|
protected |
Definition at line 258 of file pathspec.cc.
Referenced by operator=(), and ~Pathspec().
|
protected |
Definition at line 332 of file pathspec.cc.
Referenced by GetGlobString().
|
protected |
Definition at line 312 of file pathspec.cc.
Referenced by GetGlobStringSequence().
|
protected |
Definition at line 209 of file pathspec.cc.
Referenced by GetPrefixRegularExpression(), GetRegularExpression(), and GetRelaxedRegularExpression().
const std::string & Pathspec::GetGlobString | ( | ) | const |
Generates a single glob string out of this Pathspec. This string can be used in glob()
Definition at line 323 of file pathspec.cc.
const Pathspec::GlobStringSequence & Pathspec::GetGlobStringSequence | ( | ) | const |
Generates an ordered list of unix-like glob strings split on directory boundaries. Can be used to traverse down into a directory tree along a given Pathspec.
Definition at line 303 of file pathspec.cc.
Referenced by GenerateGlobString().
|
protected |
Definition at line 181 of file pathspec.cc.
Referenced by IsPathspecPrefixMatching().
|
protected |
Definition at line 168 of file pathspec.cc.
Referenced by IsPathspecMatching().
|
protected |
Definition at line 195 of file pathspec.cc.
Referenced by IsPathspecMatchingRelaxed().
|
inline |
Checks if this Pathspec is defining an absolute path (i.e. starts with /)
Definition at line 112 of file pathspec.h.
Referenced by GenerateGlobString(), GenerateRegularExpression(), IsMatching(), IsPrefixMatching(), operator==(), and catalog::Dirtab::ParsePathspec().
bool Pathspec::IsMatching | ( | const std::string & | query_path | ) | const |
Matches an exact path string. Directory boundaries are taken into account Say: wildcards do not match beyond a singly directory tree level.
query_path | the path to be matched against this Pathstring |
Definition at line 110 of file pathspec.cc.
bool Pathspec::IsMatchingRelaxed | ( | const std::string & | query_path | ) | const |
Matches path strings similar to shell pattern matching (case...esac). Say: wildcards match any character including / and therefore can span over directory boundaries.
query_path | the path to be matched against this Pathstring |
Definition at line 134 of file pathspec.cc.
|
protected |
Definition at line 144 of file pathspec.cc.
Referenced by IsMatching().
|
protected |
Definition at line 152 of file pathspec.cc.
Referenced by IsMatchingRelaxed().
|
protected |
Definition at line 148 of file pathspec.cc.
Referenced by IsPrefixMatching().
bool Pathspec::IsPrefixMatching | ( | const std::string & | query_path | ) | const |
Matches if the Pathspec is a prefix path of query_path. Directory boundaries are taken into account. Only works for absolute PathSpec.
query_path | the path to be matched against this Pathstring |
Definition at line 122 of file pathspec.cc.
|
inlinestatic |
Definition at line 135 of file pathspec.h.
Referenced by PathspecElementPattern::PlaintextSubPattern::GenerateGlobString(), PathspecElementPattern::Parse(), PathspecElementPattern::ParsePlaintext(), and PathspecElementPattern::ParseSpecialChar().
|
inline |
Checks if the parsed Pathspec is valid and can be used.
Definition at line 106 of file pathspec.h.
Referenced by IsMatching(), IsMatchingRelaxed(), IsPrefixMatching(), operator==(), and catalog::Dirtab::ParsePathspec().
|
inline |
Definition at line 133 of file pathspec.h.
bool Pathspec::operator== | ( | const Pathspec & | other | ) | const |
|
protected |
Definition at line 78 of file pathspec.cc.
Referenced by Pathspec().
|
protected |
Definition at line 95 of file pathspec.cc.
Referenced by Parse().
|
protected |
Definition at line 295 of file pathspec.cc.
Referenced by ApplyRegularExpression(), and CompileRegularExpression().
|
private |
Definition at line 182 of file pathspec.h.
Referenced by IsAbsolute(), operator=(), and Parse().
|
mutableprivate |
Definition at line 172 of file pathspec.h.
Referenced by GenerateGlobString(), GetGlobString(), and operator=().
|
mutableprivate |
Definition at line 178 of file pathspec.h.
Referenced by GetGlobString(), and operator=().
|
mutableprivate |
Definition at line 173 of file pathspec.h.
Referenced by GenerateGlobStringSequence(), GetGlobStringSequence(), and operator=().
|
mutableprivate |
Definition at line 179 of file pathspec.h.
Referenced by GetGlobStringSequence(), and operator=().
|
static |
Definition at line 50 of file pathspec.h.
Referenced by PathspecElementPattern::ParsePlaintext().
|
static |
Definition at line 52 of file pathspec.h.
Referenced by IsSpecialChar(), and PathspecElementPattern::ParseSpecialChar().
|
static |
Definition at line 49 of file pathspec.h.
Referenced by GenerateGlobString(), PathspecElementPattern::WildcardSubPattern::GenerateRegularExpression(), PathspecElementPattern::PlaceholderSubPattern::GenerateRegularExpression(), GenerateRegularExpression(), IsMatching(), IsPrefixMatching(), Parse(), and ParsePathElement().
|
static |
Definition at line 51 of file pathspec.h.
Referenced by IsSpecialChar(), and PathspecElementPattern::ParseSpecialChar().
|
private |
Definition at line 167 of file pathspec.h.
Referenced by GenerateGlobStringSequence(), GenerateRegularExpression(), operator=(), operator==(), ParsePathElement(), and Pathspec().
|
mutableprivate |
Definition at line 171 of file pathspec.h.
Referenced by GetPrefixRegularExpression().
|
mutableprivate |
Definition at line 177 of file pathspec.h.
Referenced by GetPrefixRegularExpression().
|
mutableprivate |
Definition at line 169 of file pathspec.h.
Referenced by DestroyRegularExpressions(), GetRegularExpression(), and PrintRegularExpressionError().
|
mutableprivate |
Definition at line 175 of file pathspec.h.
Referenced by DestroyRegularExpressions(), GetRegularExpression(), and PrintRegularExpressionError().
|
mutableprivate |
Definition at line 170 of file pathspec.h.
Referenced by DestroyRegularExpressions(), and GetRelaxedRegularExpression().
|
mutableprivate |
Definition at line 176 of file pathspec.h.
Referenced by DestroyRegularExpressions(), and GetRelaxedRegularExpression().
|
private |
Definition at line 181 of file pathspec.h.
Referenced by IsValid(), operator=(), and Pathspec().