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

#include <posix-source-accessor.hh>

Inheritance diagram for nix::PosixSourceAccessor:
nix::SourceAccessor nix::LocalStoreAccessor

Public Member Functions

 PosixSourceAccessor (std::filesystem::path &&root)
 
void readFile (const CanonPath &path, Sink &sink, std::function< void(uint64_t)> sizeCallback) override
 
bool pathExists (const CanonPath &path) override
 
std::optional< StatmaybeLstat (const CanonPath &path) override
 
DirEntries readDirectory (const CanonPath &path) override
 
std::string readLink (const CanonPath &path) override
 
std::optional< std::filesystem::path > getPhysicalPath (const CanonPath &path) override
 
- Public Member Functions inherited from nix::SourceAccessor
virtual std::string readFile (const CanonPath &path)
 
Stat lstat (const CanonPath &path)
 
virtual void dumpPath (const CanonPath &path, Sink &sink, PathFilter &filter=defaultPathFilter)
 
Hash hashPath (const CanonPath &path, PathFilter &filter=defaultPathFilter, HashAlgorithm ha=HashAlgorithm::SHA256)
 
bool operator== (const SourceAccessor &x) const
 
auto operator<=> (const SourceAccessor &x) const
 
void setPathDisplay (std::string displayPrefix, std::string displaySuffix="")
 
virtual std::string showPath (const CanonPath &path)
 
CanonPath resolveSymlinks (const CanonPath &path, SymlinkResolution mode=SymlinkResolution::Full)
 
virtual std::optional< time_t > getLastModified ()
 

Static Public Member Functions

static SourcePath createAtRoot (const std::filesystem::path &path)
 

Public Attributes

const std::filesystem::path root
 
time_t mtime = 0
 
- Public Attributes inherited from nix::SourceAccessor
const size_t number
 
std::string displayPrefix
 
std::string displaySuffix
 
std::optional< std::string > fingerprint
 

Additional Inherited Members

- Public Types inherited from nix::SourceAccessor
enum  Type {
  tRegular , tSymlink , tDirectory , tChar ,
  tBlock , tSocket , tFifo , tUnknown
}
 
typedef std::optional< TypeDirEntry
 
typedef std::map< std::string, DirEntry > DirEntries
 

Detailed Description

A source accessor that uses the Unix filesystem.

Member Function Documentation

◆ createAtRoot()

SourcePath nix::PosixSourceAccessor::createAtRoot ( const std::filesystem::path & path)
static

Create a PosixSourceAccessor and SourcePath corresponding to some native path.

The PosixSourceAccessor is rooted as far up the tree as possible, (e.g. on Windows it could scoped to a drive like C:\). This allows more .. parent accessing to work.

Note
When path is trusted user input, canonicalize it using std::filesystem::canonical, makeParentCanonical, std::filesystem::weakly_canonical, etc, as appropriate for the use case. At least weak canonicalization is required for the SourcePath to do anything useful at the location it points to.
A canonicalizing behavior is not built in createAtRoot so that callers do not accidentally introduce symlink-related security vulnerabilities. Furthermore, createAtRoot does not know whether the file pointed to by path should be resolved if it is itself a symlink. In other words, createAtRoot can not decide between aforementioned canonical, makeParentCanonical, etc. for its callers.

See std::filesystem::path::root_path and std::filesystem::path::relative_path.

◆ getPhysicalPath()

std::optional< std::filesystem::path > nix::PosixSourceAccessor::getPhysicalPath ( const CanonPath & path)
overridevirtual

Return a corresponding path in the root filesystem, if possible. This is only possible for filesystems that are materialized in the root filesystem.

Reimplemented from nix::SourceAccessor.

◆ maybeLstat()

std::optional< SourceAccessor::Stat > nix::PosixSourceAccessor::maybeLstat ( const CanonPath & path)
overridevirtual

Implements nix::SourceAccessor.

◆ pathExists()

bool nix::PosixSourceAccessor::pathExists ( const CanonPath & path)
overridevirtual

Reimplemented from nix::SourceAccessor.

◆ readDirectory()

SourceAccessor::DirEntries nix::PosixSourceAccessor::readDirectory ( const CanonPath & path)
overridevirtual
Note
Like readFile, this method should not follow symlinks.

Implements nix::SourceAccessor.

◆ readFile()

void nix::PosixSourceAccessor::readFile ( const CanonPath & path,
Sink & sink,
std::function< void(uint64_t)> sizeCallback )
overridevirtual

Write the contents of a file as a sink. sizeCallback must be called with the size of the file before any data is written to the sink.

Note
Like the other readFile, this method should not follow symlinks.
subclasses of SourceAccessor need to implement at least one of the readFile() variants.

Reimplemented from nix::SourceAccessor.

◆ readLink()

std::string nix::PosixSourceAccessor::readLink ( const CanonPath & path)
overridevirtual

Implements nix::SourceAccessor.

Member Data Documentation

◆ mtime

time_t nix::PosixSourceAccessor::mtime = 0

The most recent mtime seen by lstat(). This is a hack to support dumpPathAndGetMtime(). Should remove this eventually.

◆ root

const std::filesystem::path nix::PosixSourceAccessor::root

Optional root path to prefix all operations into the native file system. This allows prepending funny things like C:\ that CanonPath intentionally doesn't support.


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