Skip to content

Commit

Permalink
PosixSourceAccessor: Support roots that are not directories
Browse files Browse the repository at this point in the history
We have to support this for `fetchTree { type = "file" }` (and
probably other types of trees that can have a non-directory at the
root, like NARs).
  • Loading branch information
edolstra committed Feb 20, 2024
1 parent b00f412 commit 930b9c8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/libutil/posix-source-accessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ std::filesystem::path PosixSourceAccessor::makeAbsPath(const CanonPath & path)
{
return root.empty()
? (std::filesystem::path { path.abs() })
: path.isRoot()
? /* Don't append a slash for the root of the accessor, since
it can be a non-directory (e.g. in the case of `fetchTree
{ type = "file" }`). */
root
: root / path.rel();
}

Expand Down
1 change: 1 addition & 0 deletions tests/functional/fetchTree-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ test_fetch_file () {
tree = builtins.fetchTree { type = "file"; url = "file://$PWD/test_input"; };
in
assert (tree.narHash == "$input_hash");
assert builtins.readFile tree == "foo\n";
tree
EOF
}
Expand Down

0 comments on commit 930b9c8

Please sign in to comment.