diff --git a/src/libutil/posix-source-accessor.cc b/src/libutil/posix-source-accessor.cc index 0300de01e..f8ec7fc6b 100644 --- a/src/libutil/posix-source-accessor.cc +++ b/src/libutil/posix-source-accessor.cc @@ -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(); } diff --git a/tests/functional/fetchTree-file.sh b/tests/functional/fetchTree-file.sh index 6395c133d..be698ea35 100644 --- a/tests/functional/fetchTree-file.sh +++ b/tests/functional/fetchTree-file.sh @@ -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 }