Skip to content

Commit

Permalink
makeParentCanonical: Rethrow filesystem_error as SysError
Browse files Browse the repository at this point in the history
  • Loading branch information
roberth committed Dec 15, 2024
1 parent 69bac08 commit 8b53c6c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/libutil/file-system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -767,12 +767,16 @@ bool isExecutableFileAmbient(const fs::path & exe) {

std::filesystem::path makeParentCanonical(const std::filesystem::path & path)
{
auto parent = path.parent_path();
if (parent == path) {
// `path` is a root directory => trivially canonical
return parent;
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);
}
return std::filesystem::canonical(parent) / path.filename();
}

} // namespace nix

0 comments on commit 8b53c6c

Please sign in to comment.