Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::CanonPath Class Reference

#include <canon-path.hh>

Classes

struct  unchecked_t
struct  Iterator

Public Member Functions

 CanonPath (std::string_view raw)
 CanonPath (const char *raw)
 CanonPath (unchecked_t _, std::string path)
 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
Iterator begin () const
Iterator end () const
std::optional< CanonPathparent () 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
bool 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 fromCwd (std::string_view path=".")

Static Public Attributes

static CanonPath root = CanonPath("/")

Detailed Description

A canonical representation of a path. It ensures the following:

  • It always starts with a slash.
  • It never ends with a slash, except if the path is "/".
  • A slash is never followed by a slash (i.e. no empty components).
  • There are no components equal to '.' or '..'.

Note that the path does not need to correspond to an actually existing path, and there is no guarantee that symlinks are resolved.

Constructor & Destructor Documentation

◆ CanonPath() [1/2]

nix::CanonPath::CanonPath ( std::string_view raw)

Construct a canon path from a non-canonical path. Any '.', '..' or empty components are removed.

◆ CanonPath() [2/2]

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.

Member Function Documentation

◆ absOrEmpty()

const std::string & nix::CanonPath::absOrEmpty ( ) const
inline

Like abs(), but return an empty string if this path is '/'. Thus the returned string never ends in a slash.

◆ extend()

void nix::CanonPath::extend ( const CanonPath & x)

Append another path to this one.

◆ isAllowed()

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.)

◆ isWithin()

bool nix::CanonPath::isWithin ( const CanonPath & parent) const

Return true if this is equal to parent or a child of parent.

◆ makeRelative()

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.

◆ operator+()

CanonPath nix::CanonPath::operator+ ( const CanonPath & x) const

Concatenate two paths.

◆ operator<()

bool nix::CanonPath::operator< ( const CanonPath & x) const
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!'.

◆ pop()

void nix::CanonPath::pop ( )

Remove the last component. Panics if this path is the root.

◆ push()

void nix::CanonPath::push ( std::string_view c)

Add a path component to this one. It must not contain any slashes.


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