MCPcopy Create free account
hub / github.com/ceph/ceph / filepath

Class filepath

src/include/filepath.h:39–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37namespace ceph { class Formatter; }
38
39class filepath {
40 inodeno_t ino = 0; // base inode. ino=0 implies pure relative path.
41 std::string path; // relative path.
42 // tells get_path() whether it should prefix path with "..." to indicate that
43 // it was shortened.
44 bool trimmed = false;
45
46 /** bits - path segments
47 * this is ['a', 'b', 'c'] for both the aboslute and relative case.
48 *
49 * NOTE: this value is LAZILY maintained... i.e. it's a cache
50 */
51 mutable std::vector<std::string> bits;
52 bool encoded = false;
53
54 void rebuild_path();
55 void parse_bits() const;
56
57 public:
58 filepath() = default;
59 filepath(std::string_view p, inodeno_t i) : ino(i), path(p) {}
60 filepath(const filepath& o) {
61 ino = o.ino;
62 path = o.path;
63 bits = o.bits;
64 encoded = o.encoded;
65 }
66 filepath(inodeno_t i) : ino(i) {}
67 filepath& operator=(const char* path) {
68 set_path(path);
69 return *this;
70 }
71
72 /*
73 * if we are fed a relative path as a string, either set ino=0 (strictly
74 * relative) or 1 (absolute). throw out any leading '/'.
75 */
76 filepath(std::string_view s) { set_path(s); }
77 filepath(const char* s) { set_path(s); }
78
79 void set_path(std::string_view s, inodeno_t b) {
80 path = s;
81 ino = b;
82 }
83
84 void set_path(std::string_view s);
85
86 // accessors
87 inodeno_t get_ino() const { return ino; }
88 const std::string& get_path() const { return path; }
89 void set_trimmed();
90 std::string get_trimmed_path() const;
91 const char *c_str() const { return path.c_str(); }
92
93 int length() const { return path.length(); }
94 unsigned depth() const {
95 if (bits.empty() && path.length() > 0) parse_bits();
96 return bits.size();

Callers 1

Calls 3

emptyMethod · 0.45
lengthMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected