![]() |
Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
|
#include <canon-path.hh>
Classes | |
| struct | unchecked_t |
| class | Iterator |
Public Member Functions | |
| CanonPath (std::string_view raw) | |
| CanonPath (const char *raw) | |
| constexpr | CanonPath (unchecked_t _, std::string path) |
| CanonPath (const std::vector< std::string > &elems) | |
| CanonPath (std::string_view raw, const CanonPath &root) | |
| bool | isRoot () const |
| operator std::string_view () const | |
| const std::string & | abs () const |
| const std::string & | absOrEmpty () const |
| const char * | c_str () const |
| std::string_view | rel () const |
| const char * | rel_c_str () const |
| Iterator | begin () const |
| Iterator | end () const |
| std::optional< CanonPath > | parent () const |
| void | pop () |
| std::optional< std::string_view > | dirOf () const |
| std::optional< std::string_view > | baseName () const |
| bool | operator== (const CanonPath &x) const |
| bool | operator!= (const CanonPath &x) const |
| auto | operator<=> (const CanonPath &x) const |
| bool | isWithin (const CanonPath &parent) const |
| CanonPath | removePrefix (const CanonPath &prefix) const |
| void | extend (const CanonPath &x) |
| CanonPath | operator/ (const CanonPath &x) const |
| void | push (std::string_view c) |
| CanonPath | operator/ (std::string_view c) const |
| bool | isAllowed (const std::set< CanonPath > &allowed) const |
| std::string | makeRelative (const CanonPath &path) const |
Static Public Member Functions | |
| static CanonPath | fromFilename (std::string_view segment) |
Static Public Attributes | |
| static const CanonPath | root = CanonPath("/") |
Friends | |
| std::size_t | hash_value (const CanonPath &path) |
A canonical representation of a path. It ensures the following:
CanonPath are "virtual" Nix paths for abstract file system objects; they are always Unix-style paths, regardless of what OS Nix is running on. The / root doesn't denote the ambient host file system root, but some virtual FS root.
| nix::CanonPath::CanonPath | ( | std::string_view | raw | ) |
Construct a canon path from a non-canonical path. Any '.', '..' or empty components are removed.
| nix::CanonPath::CanonPath | ( | const std::vector< std::string > & | elems | ) |
Construct a canon path from a vector of elements.
| nix::CanonPath::CanonPath | ( | std::string_view | raw, |
| const CanonPath & | root ) |
If raw starts with a slash, return CanonPath(raw). Otherwise return a CanonPath representing root + "/" + raw.
|
inline |
Like abs(), but return an empty string if this path is '/'. Thus the returned string never ends in a slash.
| void nix::CanonPath::extend | ( | const CanonPath & | x | ) |
Append another path to this one.
|
static |
Construct a CanonPath from a single path segment. The segment must not contain any slashes and must not be . or ...
| bool nix::CanonPath::isAllowed | ( | const std::set< CanonPath > & | allowed | ) | const |
Check whether access to this path is allowed, which is the case if 1) this is within any of the allowed paths; or 2) any of the allowed paths are within this. (The latter condition ensures access to the parents of allowed paths.)
| bool nix::CanonPath::isWithin | ( | const CanonPath & | parent | ) | const |
Return true if this is equal to parent or a child of parent.
| std::string nix::CanonPath::makeRelative | ( | const CanonPath & | path | ) | const |
Return a representation x of path relative to this, i.e. CanonPath(this.makeRelative(x), this) == path.
|
inline |
Compare paths lexicographically except that path separators are sorted before any other character. That is, in the sorted order a directory is always followed directly by its children. For instance, 'foo' < 'foo/bar' < 'foo!'.
| void nix::CanonPath::pop | ( | ) |
Remove the last component. Panics if this path is the root.
| void nix::CanonPath::push | ( | std::string_view | c | ) |
Add a path component to this one. It must not contain any slashes.