mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-25 23:36:16 +02:00
Merge pull request #9363 from edolstra/symlink-regression
Fix symlink handling
This commit is contained in:
commit
3a7f024a9c
7 changed files with 19 additions and 6 deletions
|
@ -839,7 +839,7 @@ std::string showType(const Value & v);
|
||||||
/**
|
/**
|
||||||
* If `path` refers to a directory, then append "/default.nix".
|
* If `path` refers to a directory, then append "/default.nix".
|
||||||
*/
|
*/
|
||||||
SourcePath resolveExprPath(const SourcePath & path);
|
SourcePath resolveExprPath(SourcePath path);
|
||||||
|
|
||||||
struct InvalidPathError : EvalError
|
struct InvalidPathError : EvalError
|
||||||
{
|
{
|
||||||
|
|
|
@ -686,17 +686,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
|
/* If `path' is a symlink, follow it. This is so that relative
|
||||||
path references work. */
|
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 `path' refers to a directory, append `/default.nix'. */
|
||||||
if (path2.lstat().type == InputAccessor::tDirectory)
|
if (path.lstat().type == InputAccessor::tDirectory)
|
||||||
return path2 + "default.nix";
|
return path + "default.nix";
|
||||||
|
|
||||||
return path2;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
1
tests/functional/lang/eval-okay-symlink-resolution.exp
Normal file
1
tests/functional/lang/eval-okay-symlink-resolution.exp
Normal file
|
@ -0,0 +1 @@
|
||||||
|
"test"
|
1
tests/functional/lang/eval-okay-symlink-resolution.nix
Normal file
1
tests/functional/lang/eval-okay-symlink-resolution.nix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
import symlink-resolution/foo/overlays/overlay.nix
|
|
@ -0,0 +1 @@
|
||||||
|
"test"
|
1
tests/functional/lang/symlink-resolution/foo/overlays
Symbolic link
1
tests/functional/lang/symlink-resolution/foo/overlays
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../overlays
|
|
@ -0,0 +1 @@
|
||||||
|
import ../lib
|
Loading…
Reference in a new issue