From 930b9c8269e48191097abdfb83562ad9482c4230 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 19 Feb 2024 13:54:40 +0100 Subject: [PATCH] PosixSourceAccessor: Support roots that are not directories 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). --- src/libutil/posix-source-accessor.cc | 5 +++++ tests/functional/fetchTree-file.sh | 1 + 2 files changed, 6 insertions(+) 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 }