|
Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
|
#include "lix/libutil/async-io.hh"#include "lix/libutil/box_ptr.hh"#include "lix/libutil/types.hh"#include "lix/libutil/file-descriptor.hh"#include <sys/types.h>#include <sys/stat.h>#include <dirent.h>#include <unistd.h>#include <functional>#include <optional>Go to the source code of this file.
Classes | |
| struct | nix::DirEntry |
| struct | nix::CopyFileFlags |
| class | nix::AutoDelete |
| struct | nix::DIRDeleter |
Macros | |
| #define | DT_UNKNOWN 0 |
| #define | DT_REG 1 |
| #define | DT_LNK 2 |
| #define | DT_DIR 3 |
Typedefs | |
| typedef std::vector< DirEntry > | nix::DirEntries |
| typedef std::unique_ptr< DIR, DIRDeleter > | nix::AutoCloseDir |
| typedef std::function< bool(const Path &path)> | nix::PathFilter |
Functions | |
| Path | nix::getCwd () |
| Path | nix::absPath (Path path, std::optional< PathView > dir, bool resolveSymlinks) |
| Path | nix::canonPath (PathView path, bool resolveSymlinks) |
| Path | nix::realPath (Path const &path) |
| Path | nix::tildePath (Path const &path, const std::optional< Path > &home) |
| void | nix::chmodPath (const Path &path, mode_t mode) |
| Path | nix::dirOf (const PathView path) |
| std::string_view | nix::baseNameOf (std::string_view path) |
| std::string | nix::expandTilde (std::string_view path) |
| bool | nix::isInDir (std::string_view path, std::string_view dir) |
| bool | nix::isDirOrInDir (std::string_view path, std::string_view dir) |
| struct stat | nix::stat (const Path &path) |
| struct stat | nix::lstat (const Path &path) |
| std::optional< struct stat > | nix::maybeStat (const Path &path) |
| std::optional< struct stat > | nix::maybeLstat (const Path &path) |
| bool | nix::pathExists (const Path &path) |
| bool | nix::pathAccessible (const Path &path, bool resolveSymlinks) |
| Path | nix::readLink (const Path &path) |
| bool | nix::isLink (const Path &path) |
| DirEntries | nix::readDirectory (const Path &path) |
| unsigned char | nix::getFileType (const Path &path) |
| std::string | nix::readFile (const Path &path) |
| Generator< Bytes > | nix::readFileSource (const Path &path) |
| void | nix::writeFile (const Path &path, std::string_view s, mode_t mode) |
| void | nix::writeFile (const Path &path, Source &source, mode_t mode) |
| void | nix::writeFile (AutoCloseFD &fd, std::string_view s, mode_t mode) |
| kj::Promise< Result< void > > | nix::writeFile (const Path &path, AsyncInputStream &source, mode_t mode) |
| void | nix::writeFileAndSync (const Path &path, std::string_view s, mode_t mode) |
| void | nix::syncParent (const Path &path) |
| void | nix::deletePath (const Path &path) |
| void | nix::deletePathUninterruptible (const Path &path) |
| void | nix::deletePath (const Path &path, uint64_t &bytesFreed) |
| Paths | nix::createDirs (const Path &path) |
| Paths | nix::createDirs (PathView path) |
| void | nix::createSymlink (const Path &target, const Path &link) |
| void | nix::replaceSymlink (const Path &target, const Path &link) |
| void | nix::renameFile (const Path &oldName, const Path &newName) |
| void | nix::moveFile (const Path &oldName, const Path &newName) |
| void | nix::copyFile (const Path &oldPath, const Path &newPath, CopyFileFlags flags) |
| Path | nix::createTempSubdir (const Path &parent, const Path &prefix, bool includePid, bool useGlobalCounter, mode_t mode) |
| Path | nix::makeTempPath (const Path &root, const Path &suffix) |
Utiltities for working with the file sytem and file paths.
| typedef std::function<bool(const Path & path)> nix::PathFilter |
Used in various places.
| Path nix::absPath | ( | Path | path, |
| std::optional< PathView > | dir = {}, | ||
| bool | resolveSymlinks = false ) |
| std::string_view nix::baseNameOf | ( | std::string_view | path | ) |
| Path nix::canonPath | ( | PathView | path, |
| bool | resolveSymlinks = false ) |
Canonicalise a path by removing all . or .. components and double or trailing slashes. Optionally resolves all symlink components such that each component of the resulting path is not a symbolic link.
| void nix::chmodPath | ( | const Path & | path, |
| mode_t | mode ) |
Change the permissions of a path Not called chmod as it shadows and could be confused with int chmod(char *, mode_t), which does not handle errors
| void nix::copyFile | ( | const Path & | oldPath, |
| const Path & | newPath, | ||
| CopyFileFlags | flags ) |
Recursively copy the content of oldPath to newPath. If andDelete is true, then also remove oldPath (making this equivalent to moveFile, but with the guaranty that the destination will be “fresh”, with no stale inode or file descriptor pointing to it).
| Paths nix::createDirs | ( | const Path & | path | ) |
Create a directory and all its parents, if necessary. Returns the list of created directories, in order of creation.
Create a symlink. Throws if the symlink exists.
| Path nix::createTempSubdir | ( | const Path & | parent, |
| const Path & | prefix = "nix", | ||
| bool | includePid = true, | ||
| bool | useGlobalCounter = true, | ||
| mode_t | mode = 0755 ) |
Create a temporary directory in a given parent directory.
| void nix::deletePath | ( | const Path & | path | ) |
Delete a path; i.e., in the case of a directory, it is deleted recursively. It's not an error if the path does not exist. The second variant returns the number of bytes and blocks freed.
| Path nix::dirOf | ( | const PathView | path | ) |
| std::string nix::expandTilde | ( | std::string_view | path | ) |
Perform tilde expansion on a path.
| Path nix::getCwd | ( | ) |
Get the current working directory.
Throw an error if the current directory cannot get got.
| bool nix::isDirOrInDir | ( | std::string_view | path, |
| std::string_view | dir ) |
Check whether 'path' is equal to 'dir' or a descendant of 'dir'. Both paths must be canonicalized.
| bool nix::isInDir | ( | std::string_view | path, |
| std::string_view | dir ) |
Check whether 'path' is a descendant of 'dir'. Both paths must be canonicalized.
Return temporary path constructed by appending a suffix to a root path.
The constructed path looks like <root><suffix>-<pid>-<unique>. To create a path nested in a directory, provide a suffix starting with /.
| std::optional< struct stat > nix::maybeLstat | ( | const Path & | path | ) |
lstat the given path if it exists.
| std::optional< struct stat > nix::maybeStat | ( | const Path & | path | ) |
stat the given path if it exists.
Similar to 'renameFile', but fallback to a copy+remove if src and dst are on a different filesystem.
Beware that this might not be atomic because of the copy that happens behind the scenes
| bool nix::pathAccessible | ( | const Path & | path, |
| bool | resolveSymlinks = false ) |
A version of pathExists that returns false on a permission error. Useful for inferring default paths across directories that might not be readable. Optionally resolves symlinks to determine if the real path exists.
| bool nix::pathExists | ( | const Path & | path | ) |
| std::string nix::readFile | ( | const Path & | path | ) |
Read the contents of a file into a string.
| Path nix::readLink | ( | const Path & | path | ) |
Read the contents (target) of a symbolic link. The result is not in any way canonicalised.
| Path nix::realPath | ( | Path const & | path | ) |
Resolves a file path to a fully absolute path with no symbolic links.
| path | The path to resolve. If it is relative, it will be resolved relative to the process's current directory. |
Atomically create or replace a symlink.
| struct stat nix::stat | ( | const Path & | path | ) |
Get status of path.
| void nix::syncParent | ( | const Path & | path | ) |
Flush a file's parent directory to disk
Resolve a tilde path like ~/puppy.nix into an absolute path.
If home is given, it's substituted for ~/ at the start of the input path. Otherwise, an error is thrown.
If the path starts with ~ but not ~/, an error is thrown.
| void nix::writeFile | ( | const Path & | path, |
| std::string_view | s, | ||
| mode_t | mode = 0666 ) |
Write a string to a file.
| void nix::writeFileAndSync | ( | const Path & | path, |
| std::string_view | s, | ||
| mode_t | mode = 0666 ) |
Write a string to a file and flush the file and its parents direcotry to disk.