| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/** |
| 2 |
|
|
* This file is part of the CernVM File System. |
| 3 |
|
|
*/ |
| 4 |
|
|
|
| 5 |
|
|
#ifndef CVMFS_PATH_FILTERS_INCLUSION_SPEC_H_ |
| 6 |
|
|
#define CVMFS_PATH_FILTERS_INCLUSION_SPEC_H_ |
| 7 |
|
|
|
| 8 |
|
|
#include <string> |
| 9 |
|
|
|
| 10 |
|
|
#include "path_filters/relaxed_path_filter.h" |
| 11 |
|
|
|
| 12 |
|
|
namespace catalog { |
| 13 |
|
|
|
| 14 |
|
|
/** |
| 15 |
|
|
* InclusionSpec implements a versioned inclusion specification for partial |
| 16 |
|
|
* replication of CVMFS Stratum-1 servers. |
| 17 |
|
|
* |
| 18 |
|
|
* The spec file format: |
| 19 |
|
|
* version 1 |
| 20 |
|
|
* # comment |
| 21 |
|
|
* /path/to/include |
| 22 |
|
|
* !/path/to/exclude |
| 23 |
|
|
* |
| 24 |
|
|
* Paths listed (without !) are INCLUDED in object replication. Paths prefixed |
| 25 |
|
|
* with ! are excluded (negating a parent inclusion). Anything not covered by |
| 26 |
|
|
* an inclusion rule is excluded. All catalogs are always replicated; only data |
| 27 |
|
|
* object downloads are skipped for excluded paths. |
| 28 |
|
|
* |
| 29 |
|
|
* Internally, this wraps a RelaxedPathFilter: positive rules in the spec mean |
| 30 |
|
|
* "include" (replicate objects, also covering parent and sub paths), while ! |
| 31 |
|
|
* rules mean "exclude" (skip objects). IsExcluded() returns the negation of the |
| 32 |
|
|
* filter match. |
| 33 |
|
|
* |
| 34 |
|
|
* Only paths that correspond to nested catalog transition points are |
| 35 |
|
|
* meaningful. Paths that don't align with catalog boundaries will trigger |
| 36 |
|
|
* warnings during snapshot and be rounded up to the enclosing catalog. |
| 37 |
|
|
*/ |
| 38 |
|
|
class InclusionSpec { |
| 39 |
|
|
public: |
| 40 |
|
|
static const int kCurrentVersion = 1; |
| 41 |
|
|
|
| 42 |
|
|
InclusionSpec(); |
| 43 |
|
|
~InclusionSpec(); |
| 44 |
|
|
|
| 45 |
|
|
/** |
| 46 |
|
|
* Creates an InclusionSpec from a file on disk. |
| 47 |
|
|
* Returns NULL on failure (file not found, parse error). |
| 48 |
|
|
* Caller takes ownership. |
| 49 |
|
|
*/ |
| 50 |
|
|
static InclusionSpec *Create(const std::string &spec_path); |
| 51 |
|
|
|
| 52 |
|
|
/** |
| 53 |
|
|
* Parse a spec string. Returns true on success. |
| 54 |
|
|
*/ |
| 55 |
|
|
bool Parse(const std::string &spec); |
| 56 |
|
|
|
| 57 |
|
|
/** |
| 58 |
|
|
* Returns true if the given path should have its data objects |
| 59 |
|
|
* EXCLUDED from replication (i.e., objects should NOT be downloaded). |
| 60 |
|
|
* |
| 61 |
|
|
* The root path "" or "/" is never excluded. |
| 62 |
|
|
*/ |
| 63 |
|
|
bool IsExcluded(const std::string &path) const; |
| 64 |
|
|
|
| 65 |
|
|
/** |
| 66 |
|
|
* Returns true if parsing succeeded and version is supported. |
| 67 |
|
|
*/ |
| 68 |
|
492 |
bool IsValid() const { return valid_; } |
| 69 |
|
|
|
| 70 |
|
|
/** |
| 71 |
|
|
* Returns the parsed version number, or -1 if not parsed. |
| 72 |
|
|
*/ |
| 73 |
|
164 |
int version() const { return version_; } |
| 74 |
|
|
|
| 75 |
|
|
/** |
| 76 |
|
|
* Returns the original spec content for upload to backend storage. |
| 77 |
|
|
*/ |
| 78 |
|
41 |
const std::string &content() const { return content_; } |
| 79 |
|
|
|
| 80 |
|
|
private: |
| 81 |
|
|
bool ParseVersion(const std::string &line); |
| 82 |
|
|
std::string StripVersionLine(const std::string &spec) const; |
| 83 |
|
|
|
| 84 |
|
|
bool valid_; |
| 85 |
|
|
int version_; |
| 86 |
|
|
std::string content_; |
| 87 |
|
|
RelaxedPathFilter filter_; |
| 88 |
|
|
}; |
| 89 |
|
|
|
| 90 |
|
|
} // namespace catalog |
| 91 |
|
|
|
| 92 |
|
|
#endif // CVMFS_PATH_FILTERS_INCLUSION_SPEC_H_ |
| 93 |
|
|
|