1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-11 21:16:02 +01:00

Add makeParentCanonical()

(cherry picked from commit 69853c067c)
This commit is contained in:
Robert Hensing 2024-12-13 18:37:25 +01:00 committed by Jörg Thalheim
parent 2c89c38fa1
commit fa3fd41063
3 changed files with 44 additions and 0 deletions

View file

@ -101,6 +101,23 @@ std::optional<struct stat> maybeLstat(const Path & path);
*/
bool pathExists(const Path & path);
/**
* Canonicalize a path except for the last component.
*
* This is useful for getting the canonical location of a symlink.
*
* Consider the case where `foo/l` is a symlink. `canonical("foo/l")` will
* resolve the symlink `l` to its target.
* `makeParentCanonical("foo/l")` will not resolve the symlink `l` to its target,
* but does ensure that the returned parent part of the path, `foo` is resolved
* to `canonical("foo")`, and can therefore be retrieved without traversing any
* symlinks.
*
* If a relative path is passed, it will be made absolute, so that the parent
* can always be canonicalized.
*/
std::filesystem::path makeParentCanonical(const std::filesystem::path & path);
/**
* A version of pathExists that returns false on a permission error.
* Useful for inferring default paths across directories that might not