#include <posix-source-accessor.hh>
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< Stat > | maybeLstat (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 |
![]() | |
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 |
![]() | |
const size_t | number |
std::string | displayPrefix |
std::string | displaySuffix |
std::optional< std::string > | fingerprint |
Additional Inherited Members | |
![]() | |
enum | Type { tRegular , tSymlink , tDirectory , tChar , tBlock , tSocket , tFifo , tUnknown } |
typedef std::optional< Type > | DirEntry |
typedef std::map< std::string, DirEntry > | DirEntries |
A source accessor that uses the Unix filesystem.
|
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.
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.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
.
|
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.
|
overridevirtual |
Implements nix::SourceAccessor.
|
overridevirtual |
Reimplemented from nix::SourceAccessor.
|
overridevirtual |
readFile
, this method should not follow symlinks. Implements nix::SourceAccessor.
|
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.
readFile
, this method should not follow symlinks.SourceAccessor
need to implement at least one of the readFile()
variants. Reimplemented from nix::SourceAccessor.
|
overridevirtual |
Implements nix::SourceAccessor.
time_t nix::PosixSourceAccessor::mtime = 0 |
The most recent mtime seen by lstat(). This is a hack to support dumpPathAndGetMtime(). Should remove this eventually.
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.