Skip to content

Commit 7096acc

Browse files
committed
Parser: Respect the accessor of the source file for relative paths
Previously we only returned paths in rootFS, which is wrong and only worked because currently all our source trees are in rootFS.
1 parent 5c6785e commit 7096acc

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/libexpr/parser.y

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,18 @@ string_parts_interpolated
359359

360360
path_start
361361
: PATH {
362-
Path path(absPath(std::string_view{$1.p, $1.l}, state->basePath.path.abs()));
362+
std::string_view literal({$1.p, $1.l});
363+
Path path(absPath(literal, state->basePath.path.abs()));
363364
/* add back in the trailing '/' to the first segment */
364-
if ($1.p[$1.l-1] == '/' && $1.l > 1)
365-
path += "/";
366-
$$ = new ExprPath(ref<SourceAccessor>(state->rootFS), std::move(path));
365+
if (literal.size() > 1 && literal.back() == '/')
366+
path += '/';
367+
$$ =
368+
/* Absolute paths are always interpreted relative to the
369+
root filesystem accessor, rather than the accessor of the
370+
current Nix expression. */
371+
literal.front() == '/'
372+
? new ExprPath(state->rootFS, std::move(path))
373+
: new ExprPath(state->basePath.accessor, std::move(path));
367374
}
368375
| HPATH {
369376
if (state->settings.pureEval) {

0 commit comments

Comments
 (0)