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 19, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent d022bce commit 7eb3ba0
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
@@ -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();
}

1 change: 1 addition & 0 deletions tests/functional/fetchTree-file.sh
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 7eb3ba0

Please sign in to comment.