mirror of
https://github.com/NixOS/nix.git
synced 2025-11-11 13:06:01 +01:00
parent
2c89c38fa1
commit
fa3fd41063
3 changed files with 44 additions and 0 deletions
|
|
@ -685,4 +685,19 @@ void moveFile(const Path & oldName, const Path & newName)
|
|||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::filesystem::path makeParentCanonical(const std::filesystem::path & rawPath)
|
||||
{
|
||||
std::filesystem::path path(absPath(rawPath.string()));;
|
||||
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