From b14f88e0d46c61280a69da9559cf54cbce058eb5 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Thu, 7 Mar 2024 04:06:03 +0100 Subject: Merge pull request #9985 from alois31/symlink-resolution Restore `builtins.pathExists` behavior on broken symlinks (cherry picked from commit d53c8901ef7f2033855dd99063522e3d56a19dab) === note that this variant differs markedly from the source commit because we haven't endured quite as much lazy trees. Change-Id: I0facf282f21fe0db4134be5c65a8368c1b3a06fc --- src/libexpr/primops.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/libexpr') diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 1a961582f..c4fdc6098 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -1540,11 +1540,12 @@ static void prim_pathExists(EvalState & state, const PosIdx pos, Value * * args, || arg.str().ends_with("/.")); try { - auto checked = state.checkSourcePath(path); - auto exists = checked.pathExists(); - if (exists && mustBeDir) { - exists = checked.lstat().type == InputAccessor::tDirectory; - } + auto checked = state + .checkSourcePath(path) + .resolveSymlinks(mustBeDir ? SymlinkResolution::Full : SymlinkResolution::Ancestors); + + auto st = checked.maybeLstat(); + auto exists = st && (!mustBeDir || st->type == InputAccessor::tDirectory); v.mkBool(exists); } catch (SysError & e) { /* Don't give away info from errors while canonicalising -- cgit v1.2.3