Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
nix::ExecutablePath Struct Reference

#include <executable-path.hh>

Public Member Functions

OsString render () const
 
std::optional< std::filesystem::path > findName (const OsString &exe, std::function< bool(const std::filesystem::path &)> isExecutableFile=isExecutableFileAmbient) const
 
std::filesystem::path findPath (const std::filesystem::path &exe, std::function< bool(const std::filesystem::path &)> isExecutable=isExecutableFileAmbient) const
 
bool operator== (const ExecutablePath &) const =default
 

Static Public Member Functions

static ExecutablePath parse (const OsString &path)
 
static ExecutablePath load ()
 

Public Attributes

std::vector< std::filesystem::path > directories
 

Static Public Attributes

static constexpr const OsChar separator
 

Detailed Description

Todo
rename, it is not just good for execuatable paths, but also other lists of paths.

Member Function Documentation

◆ findName()

std::optional< fs::path > nix::ExecutablePath::findName ( const OsString & exe,
std::function< bool(const std::filesystem::path &)> isExecutableFile = isExecutableFileAmbient ) const

Search for an executable.

For Unix, this is according to the POSIX spec for PATH. https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03

Parameters
exeThis must just be a name, and not contain any / (or \ on Windows). in case it does, per the spec no lookup should be perfomed, and the path (it is not just a file name) as is. This is the caller's respsonsibility.

This is a pure function, except for the default isExecutable argument, which uses the ambient file system to check if a file is executable (and exists).

Returns
path to a resolved executable

◆ findPath()

fs::path nix::ExecutablePath::findPath ( const std::filesystem::path & exe,
std::function< bool(const std::filesystem::path &)> isExecutable = isExecutableFileAmbient ) const

Like the findName but also allows a file path as input.

This implements the full POSIX spec: if the path is just a name, it searches like the above. Otherwise, it returns the path as is. If (in the name case) the search fails, an exception is thrown.

◆ load()

ExecutablePath nix::ExecutablePath::load ( )
static

Load the PATH environment variable and parse it.

◆ parse()

ExecutablePath nix::ExecutablePath::parse ( const OsString & path)
static

Parse path into a list of paths.

On Unix we split on :, on Windows we split on ;.

For Unix, this is according to the POSIX spec for PATH. https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03

◆ render()

OsString nix::ExecutablePath::render ( ) const

Opposite of parse

Member Data Documentation

◆ separator

const OsChar nix::ExecutablePath::separator
staticconstexpr
Initial value:
=
':'

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