CernVM-FS  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Pathspec Class Reference

#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 GlobStringSequenceGetGlobStringSequence () const
 
const std::string & GetGlobString () const
 
Pathspecoperator= (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 &regex) const
 
void PrintRegularExpressionError (const int error_code) const
 
void GenerateGlobStringSequence () const
 
void GenerateGlobString () const
 
void DestroyRegularExpressions ()
 

Private Attributes

ElementPatterns patterns_
 
bool regex_compiled_
 
regex_t * regex_
 
bool relaxed_regex_compiled_
 
regex_t * relaxed_regex_
 
bool prefix_regex_compiled_
 
regex_t * prefix_regex_
 
bool glob_string_compiled_
 
std::string glob_string_
 
bool glob_string_sequence_compiled_
 
GlobStringSequence glob_string_sequence_
 
bool valid_
 
bool absolute_
 

Detailed Description

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.

Member Typedef Documentation

typedef std::vector<PathspecElementPattern> Pathspec::ElementPatterns
protected

Definition at line 55 of file pathspec.h.

typedef std::vector<std::string> Pathspec::GlobStringSequence

Definition at line 58 of file pathspec.h.

Constructor & Destructor Documentation

Pathspec::Pathspec ( const std::string &  spec)
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()

Parameters
specthe pathspec pattern to be parsed

This file is part of the CernVM File System.

Definition at line 12 of file pathspec.cc.

Here is the call graph for this function:

Pathspec::Pathspec ( const Pathspec other)

Definition at line 38 of file pathspec.cc.

Pathspec::~Pathspec ( )

Definition at line 53 of file pathspec.cc.

Here is the call graph for this function:

Member Function Documentation

bool Pathspec::ApplyRegularExpression ( const std::string &  query_path,
regex_t *  regex 
) const
protected

Definition at line 154 of file pathspec.cc.

Referenced by IsPathspecMatching(), IsPathspecMatchingRelaxed(), and IsPathspecPrefixMatching().

Here is the call graph for this function:

Here is the caller graph for this function:

regex_t * Pathspec::CompileRegularExpression ( const std::string &  regex) const
protected

Definition at line 243 of file pathspec.cc.

Referenced by GetPrefixRegularExpression(), GetRegularExpression(), and GetRelaxedRegularExpression().

Here is the call graph for this function:

Here is the caller graph for this function:

void Pathspec::DestroyRegularExpressions ( )
protected

Definition at line 256 of file pathspec.cc.

Referenced by operator=(), and ~Pathspec().

Here is the call graph for this function:

Here is the caller graph for this function:

void Pathspec::GenerateGlobString ( ) const
protected

Definition at line 330 of file pathspec.cc.

Referenced by GetGlobString().

Here is the call graph for this function:

Here is the caller graph for this function:

void Pathspec::GenerateGlobStringSequence ( ) const
protected

Definition at line 310 of file pathspec.cc.

Referenced by GetGlobStringSequence().

Here is the call graph for this function:

Here is the caller graph for this function:

std::string Pathspec::GenerateRegularExpression ( const bool  is_relaxed = false,
const bool  is_prefix = false 
) const
protected

Definition at line 207 of file pathspec.cc.

Referenced by GetPrefixRegularExpression(), GetRegularExpression(), and GetRelaxedRegularExpression().

Here is the call graph for this function:

Here is the caller graph for this function:

const std::string & Pathspec::GetGlobString ( ) const

Generates a single glob string out of this Pathspec. This string can be used in glob()

Returns
a unix-compatible glob string

Definition at line 321 of file pathspec.cc.

Here is the call graph for this function:

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.

Returns
an ordered list of unixoid glob strings (usable in glob())

Definition at line 301 of file pathspec.cc.

Referenced by GenerateGlobString().

Here is the call graph for this function:

Here is the caller graph for this function:

regex_t * Pathspec::GetPrefixRegularExpression ( ) const
protected

Definition at line 179 of file pathspec.cc.

Referenced by IsPathspecPrefixMatching().

Here is the call graph for this function:

Here is the caller graph for this function:

regex_t * Pathspec::GetRegularExpression ( ) const
protected

Definition at line 166 of file pathspec.cc.

Referenced by IsPathspecMatching().

Here is the call graph for this function:

Here is the caller graph for this function:

regex_t * Pathspec::GetRelaxedRegularExpression ( ) const
protected

Definition at line 193 of file pathspec.cc.

Referenced by IsPathspecMatchingRelaxed().

Here is the call graph for this function:

Here is the caller graph for this function:

bool Pathspec::IsAbsolute ( ) const
inline

Checks if this Pathspec is defining an absolute path (i.e. starts with /)

Returns
true if this Pathspec is absolute

Definition at line 112 of file pathspec.h.

Referenced by GenerateGlobString(), GenerateRegularExpression(), IsMatching(), IsPrefixMatching(), operator==(), and catalog::Dirtab::ParsePathspec().

Here is the caller graph for this function:

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.

Parameters
query_paththe path to be matched against this Pathstring
Returns
true if the path matches

Definition at line 108 of file pathspec.cc.

Here is the call graph for this function:

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.

Parameters
query_paththe path to be matched against this Pathstring
Returns
true if the path matches

Definition at line 132 of file pathspec.cc.

Here is the call graph for this function:

bool Pathspec::IsPathspecMatching ( const std::string &  query_path) const
protected

Definition at line 142 of file pathspec.cc.

Referenced by IsMatching().

Here is the call graph for this function:

Here is the caller graph for this function:

bool Pathspec::IsPathspecMatchingRelaxed ( const std::string &  query_path) const
protected

Definition at line 150 of file pathspec.cc.

Referenced by IsMatchingRelaxed().

Here is the call graph for this function:

Here is the caller graph for this function:

bool Pathspec::IsPathspecPrefixMatching ( const std::string &  query_path) const
protected

Definition at line 146 of file pathspec.cc.

Referenced by IsPrefixMatching().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
query_paththe path to be matched against this Pathstring
Returns
true if the path matches

Definition at line 120 of file pathspec.cc.

Here is the call graph for this function:

static bool Pathspec::IsSpecialChar ( const char  chr)
inlinestatic
bool Pathspec::IsValid ( ) const
inline

Checks if the parsed Pathspec is valid and can be used.

Returns
true if this Pathspec is valid

Definition at line 106 of file pathspec.h.

Referenced by IsMatching(), IsMatchingRelaxed(), IsPrefixMatching(), operator==(), and catalog::Dirtab::ParsePathspec().

Here is the caller graph for this function:

bool Pathspec::operator!= ( const Pathspec other) const
inline

Definition at line 133 of file pathspec.h.

Pathspec & Pathspec::operator= ( const Pathspec other)

Definition at line 57 of file pathspec.cc.

Here is the call graph for this function:

bool Pathspec::operator== ( const Pathspec other) const

Definition at line 272 of file pathspec.cc.

Here is the call graph for this function:

void Pathspec::Parse ( const std::string &  spec)
protected

Definition at line 76 of file pathspec.cc.

Referenced by Pathspec().

Here is the call graph for this function:

Here is the caller graph for this function:

void Pathspec::ParsePathElement ( const std::string::const_iterator &  end,
std::string::const_iterator *  itr 
)
protected

Definition at line 93 of file pathspec.cc.

Referenced by Parse().

Here is the caller graph for this function:

void Pathspec::PrintRegularExpressionError ( const int  error_code) const
protected

Definition at line 293 of file pathspec.cc.

Referenced by ApplyRegularExpression(), and CompileRegularExpression().

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

bool Pathspec::absolute_
private

Definition at line 185 of file pathspec.h.

Referenced by IsAbsolute(), operator=(), and Parse().

std::string Pathspec::glob_string_
mutableprivate

Definition at line 179 of file pathspec.h.

Referenced by GenerateGlobString(), GetGlobString(), and operator=().

bool Pathspec::glob_string_compiled_
mutableprivate

Definition at line 178 of file pathspec.h.

Referenced by GetGlobString(), and operator=().

GlobStringSequence Pathspec::glob_string_sequence_
mutableprivate

Definition at line 182 of file pathspec.h.

Referenced by GenerateGlobStringSequence(), GetGlobStringSequence(), and operator=().

bool Pathspec::glob_string_sequence_compiled_
mutableprivate

Definition at line 181 of file pathspec.h.

Referenced by GetGlobStringSequence(), and operator=().

const char Pathspec::kEscaper = '\\'
static

Definition at line 50 of file pathspec.h.

Referenced by PathspecElementPattern::ParsePlaintext().

const char Pathspec::kPlaceholder = '?'
static

Definition at line 52 of file pathspec.h.

Referenced by IsSpecialChar(), and PathspecElementPattern::ParseSpecialChar().

const char Pathspec::kWildcard = '*'
static

Definition at line 51 of file pathspec.h.

Referenced by IsSpecialChar(), and PathspecElementPattern::ParseSpecialChar().

ElementPatterns Pathspec::patterns_
private
regex_t* Pathspec::prefix_regex_
mutableprivate

Definition at line 176 of file pathspec.h.

Referenced by GetPrefixRegularExpression().

bool Pathspec::prefix_regex_compiled_
mutableprivate

Definition at line 175 of file pathspec.h.

Referenced by GetPrefixRegularExpression().

regex_t* Pathspec::regex_
mutableprivate
bool Pathspec::regex_compiled_
mutableprivate
regex_t* Pathspec::relaxed_regex_
mutableprivate

Definition at line 173 of file pathspec.h.

Referenced by DestroyRegularExpressions(), and GetRelaxedRegularExpression().

bool Pathspec::relaxed_regex_compiled_
mutableprivate

Definition at line 172 of file pathspec.h.

Referenced by DestroyRegularExpressions(), and GetRelaxedRegularExpression().

bool Pathspec::valid_
private

Definition at line 184 of file pathspec.h.

Referenced by IsValid(), operator=(), and Pathspec().


The documentation for this class was generated from the following files: