mirror of
https://github.com/NixOS/nix
synced 2025-06-25 23:11:16 +02:00
Add makeParentCanonical()
This commit is contained in:
parent
6827768807
commit
69853c067c
3 changed files with 44 additions and 0 deletions
|
@ -766,4 +766,19 @@ bool isExecutableFileAmbient(const fs::path & exe) {
|
|||
) == 0;
|
||||
}
|
||||
|
||||
std::filesystem::path makeParentCanonical(const std::filesystem::path & rawPath)
|
||||
{
|
||||
std::filesystem::path path(absPath(rawPath));;
|
||||
try {
|
||||
auto parent = path.parent_path();
|
||||
if (parent == path) {
|
||||
// `path` is a root directory => trivially canonical
|
||||
return parent;
|
||||
}
|
||||
return std::filesystem::canonical(parent) / path.filename();
|
||||
} catch (fs::filesystem_error & e) {
|
||||
throw SysError("canonicalising parent path of '%1%'", path);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace nix
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue