Skip to content

Commit

Permalink
Fix symlink handling
Browse files Browse the repository at this point in the history
This restores the symlink handling behaviour prior to
94812cc.

Fixes #9298.

(cherry picked from commit 31ebc60)
  • Loading branch information
edolstra authored and github-actions[bot] committed Jan 21, 2024
1 parent 60eb805 commit bef68e5
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/libexpr/eval.hh
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ std::string showType(const Value & v);
/**
* If `path` refers to a directory, then append "/default.nix".
*/
SourcePath resolveExprPath(const SourcePath & path);
SourcePath resolveExprPath(SourcePath path);

struct InvalidPathError : EvalError
{
Expand Down
18 changes: 13 additions & 5 deletions src/libexpr/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -682,17 +682,25 @@ Expr * EvalState::parse(
}


SourcePath resolveExprPath(const SourcePath & path)
SourcePath resolveExprPath(SourcePath path)
{
unsigned int followCount = 0, maxFollow = 1024;

/* If `path' is a symlink, follow it. This is so that relative
path references work. */
auto path2 = path.resolveSymlinks();
while (true) {
// Basic cycle/depth limit to avoid infinite loops.
if (++followCount >= maxFollow)
throw Error("too many symbolic links encountered while traversing the path '%s'", path);
if (path.lstat().type != InputAccessor::tSymlink) break;
path = {path.accessor, CanonPath(path.readLink(), path.path.parent().value_or(CanonPath::root))};
}

/* If `path' refers to a directory, append `/default.nix'. */
if (path2.lstat().type == InputAccessor::tDirectory)
return path2 + "default.nix";
if (path.lstat().type == InputAccessor::tDirectory)
return path + "default.nix";

return path2;
return path;
}


Expand Down
1 change: 1 addition & 0 deletions tests/functional/lang/eval-okay-symlink-resolution.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"test"
1 change: 1 addition & 0 deletions tests/functional/lang/eval-okay-symlink-resolution.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import symlink-resolution/foo/overlays/overlay.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"test"
1 change: 1 addition & 0 deletions tests/functional/lang/symlink-resolution/foo/overlays
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import ../lib

0 comments on commit bef68e5

Please sign in to comment.