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

#include <source-accessor.hh>

Inheritance diagram for nix::SourceAccessor:
nix::FilteringSourceAccessor nix::GitSourceAccessor nix::MemorySourceAccessor nix::MountedSourceAccessor nix::NarAccessor nix::PosixSourceAccessor nix::RemoteFSAccessor nix::AllowListSourceAccessor nix::CachingFilteringSourceAccessor nix::LocalStoreAccessor nix::AllowListSourceAccessorImpl nix::GitExportIgnoreSourceAccessor

Classes

struct  Stat
 

Public Types

enum  Type {
  tRegular , tSymlink , tDirectory , tChar ,
  tBlock , tSocket , tFifo , tUnknown
}
 
typedef std::optional< TypeDirEntry
 
typedef std::map< std::string, DirEntry > DirEntries
 

Public Member Functions

virtual std::string readFile (const CanonPath &path)
 
virtual void readFile (const CanonPath &path, Sink &sink, std::function< void(uint64_t)> sizeCallback=[](uint64_t size){})
 
virtual bool pathExists (const CanonPath &path)
 
Stat lstat (const CanonPath &path)
 
virtual std::optional< StatmaybeLstat (const CanonPath &path)=0
 
virtual DirEntries readDirectory (const CanonPath &path)=0
 
virtual std::string readLink (const CanonPath &path)=0
 
virtual void dumpPath (const CanonPath &path, Sink &sink, PathFilter &filter=defaultPathFilter)
 
Hash hashPath (const CanonPath &path, PathFilter &filter=defaultPathFilter, HashAlgorithm ha=HashAlgorithm::SHA256)
 
virtual std::optional< std::filesystem::path > getPhysicalPath (const CanonPath &path)
 
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 ()
 

Public Attributes

const size_t number
 
std::string displayPrefix
 
std::string displaySuffix
 
std::optional< std::string > fingerprint
 

Detailed Description

A read-only filesystem abstraction. This is used by the Nix evaluator and elsewhere for accessing sources in various filesystem-like entities (such as the real filesystem, tarballs or Git repositories).

Member Enumeration Documentation

◆ Type

Enumerator
tChar 

Any other node types that may be encountered on the file system, such as device nodes, sockets, named pipe, and possibly even more exotic things.

Responsible for "unknown" from builtins.readFileType "/dev/null".

Unlike DT_UNKNOWN, this must not be used for deferring the lookup of types.

Member Function Documentation

◆ getLastModified()

virtual std::optional< time_t > nix::SourceAccessor::getLastModified ( )
inlinevirtual

Return the maximum last-modified time of the files in this tree, if available.

◆ getPhysicalPath()

virtual std::optional< std::filesystem::path > nix::SourceAccessor::getPhysicalPath ( const CanonPath & path)
inlinevirtual

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

Reimplemented in nix::FilteringSourceAccessor, and nix::PosixSourceAccessor.

◆ readDirectory()

virtual DirEntries nix::SourceAccessor::readDirectory ( const CanonPath & path)
pure virtual

◆ readFile() [1/2]

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

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

Reimplemented in nix::FilteringSourceAccessor, nix::GitSourceAccessor, nix::MemorySourceAccessor, nix::MountedSourceAccessor, nix::NarAccessor, and nix::RemoteFSAccessor.

◆ readFile() [2/2]

void nix::SourceAccessor::readFile ( const CanonPath & path,
Sink & sink,
std::function< void(uint64_t)> sizeCallback = [](uint64_t size){} )
virtual

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 in nix::LocalStoreAccessor, and nix::PosixSourceAccessor.

◆ resolveSymlinks()

CanonPath nix::SourceAccessor::resolveSymlinks ( const CanonPath & path,
SymlinkResolution mode = SymlinkResolution::Full )

Resolve any symlinks in path according to the given resolution mode.

Parameters
modemight only be a temporary solution for this. See the discussion in https://github.com/NixOS/nix/pull/9985.

Member Data Documentation

◆ fingerprint

std::optional<std::string> nix::SourceAccessor::fingerprint

A string that uniquely represents the contents of this accessor. This is used for caching lookups (see fetchToStore()).


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