Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::FilteringSourceAccessor Struct Referenceabstract

#include <filtering-source-accessor.hh>

Inheritance diagram for nix::FilteringSourceAccessor:
nix::SourceAccessor nix::AllowListSourceAccessor nix::CachingFilteringSourceAccessor nix::AllowListSourceAccessorImpl nix::GitExportIgnoreSourceAccessor

Public Member Functions

 FilteringSourceAccessor (const SourcePath &src, MakeNotAllowedError &&makeNotAllowedError)
std::optional< std::filesystem::path > getPhysicalPath (const CanonPath &path) override
void readFile (const CanonPath &path, Sink &sink, fun< void(uint64_t)> sizeCallback) override
bool pathExists (const CanonPath &path) override
 Check whether a file exists at path.
Stat lstat (const CanonPath &path) override
std::optional< Stat > maybeLstat (const CanonPath &path) override
DirEntries readDirectory (const CanonPath &path) override
std::string readLink (const CanonPath &path) override
std::string showPath (const CanonPath &path) override
 Render a human-readable representation of the accessor + path beneath it.
std::pair< CanonPath, std::optional< std::string > > getFingerprint (const CanonPath &path) override
void invalidateCache () override
void checkAccess (const CanonPath &path)
virtual bool isAllowed (const CanonPath &path)=0
std::string readFile (const CanonPath &path)
Public Member Functions inherited from nix::SourceAccessor
std::string readFile (const CanonPath &path)
virtual void readDirectory (const CanonPath &dirPath, std::function< void(SourceAccessor &subdirAccessor, const CanonPath &subdirRelPath)> callback)
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="")
CanonPath resolveSymlinks (const CanonPath &path, SymlinkResolution mode=SymlinkResolution::Full)
virtual std::optional< time_t > getLastModified ()

Public Attributes

ref< SourceAccessor > next
CanonPath prefix
MakeNotAllowedError makeNotAllowedError
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< Type > DirEntry
typedef std::map< std::string, DirEntry > DirEntries

Detailed Description

An abstract wrapping SourceAccessor that performs access control. Subclasses should override isAllowed() to implement an access control policy. The error message is customized at construction.

Member Function Documentation

◆ checkAccess()

void nix::FilteringSourceAccessor::checkAccess ( const CanonPath & path)

Call makeNotAllowedError to throw a RestrictedPathError exception if isAllowed() returns false for path.

◆ getFingerprint()

std::pair< CanonPath, std::optional< std::string > > nix::FilteringSourceAccessor::getFingerprint ( const CanonPath & path)
overridevirtual

Return the fingerprint for path. This is usually the fingerprint of the current accessor, but for composite accessors (like MountedSourceAccessor), we want to return the fingerprint of the "inner" accessor if the current one lacks a fingerprint.

So this method is intended to return the most-outer accessor that has a fingerprint for path. It also returns the path that path corresponds to in that accessor.

For example: in a MountedSourceAccessor that has /nix/store/foo mounted, getFingerprint("/nix/store/foo/bar") will return the path /bar and the fingerprint of the /nix/store/foo accessor.

Reimplemented from nix::SourceAccessor.

◆ getPhysicalPath()

std::optional< std::filesystem::path > nix::FilteringSourceAccessor::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.

◆ invalidateCache()

void nix::FilteringSourceAccessor::invalidateCache ( )
inlineoverridevirtual

Drop any cached state that could go stale across external filesystem mutation (e.g. cached directory fds).

Reimplemented from nix::SourceAccessor.

◆ isAllowed()

virtual bool nix::FilteringSourceAccessor::isAllowed ( const CanonPath & path)
pure virtual

Return true iff access to path is allowed.

Implemented in nix::AllowListSourceAccessorImpl, and nix::CachingFilteringSourceAccessor.

◆ lstat()

SourceAccessor::Stat nix::FilteringSourceAccessor::lstat ( const CanonPath & path)
overridevirtual

Reimplemented from nix::SourceAccessor.

◆ maybeLstat()

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

Implements nix::SourceAccessor.

◆ pathExists()

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

Check whether a file exists at path.

Todo
Consider making this non-virtual, since the evaluator uses maybeLstat as an indication that a file exists always (for positive caching purposes).

Reimplemented from nix::SourceAccessor.

◆ readDirectory()

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

Implements nix::SourceAccessor.

◆ readFile() [1/2]

std::string nix::SourceAccessor::readFile ( const CanonPath & path)

Return the contents of a file as a string.

Note
Unlike Unix, this method should not follow symlinks. Nix by default wants to manipulate symlinks explicitly, and not implicitly follow them, as they are frequently untrusted user data and thus may point to arbitrary locations. Acting on the targets targets of symlinks should only occasionally be done, and only with care.

◆ readFile() [2/2]

void nix::FilteringSourceAccessor::readFile ( const CanonPath & path,
Sink & sink,
fun< 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.

Implements nix::SourceAccessor.

◆ readLink()

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

Implements nix::SourceAccessor.

◆ showPath()

std::string nix::FilteringSourceAccessor::showPath ( const CanonPath & path)
overridevirtual

Render a human-readable representation of the accessor + path beneath it.

Warning
The output from this function is not considered stable and is primarily useful for error messages. In libexpr, we still have a single filesystem root (modulo builtin <nix/...> filesystem root). Prefer to render paths there directly from CanonPath when paths reside in the global root filesystem.

Reimplemented from nix::SourceAccessor.


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