aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2023-09-01 13:15:54 +0200
committerGitHub <noreply@github.com>2023-09-01 13:15:54 +0200
commitb88784278fcd5c2d0bec077d6baaa0ec3f71b28f (patch)
tree681e2c5bac8118052f5690a4dc5f479ca901553e /src/libexpr
parent46478b44ffb477387235b3c597c24178845fb2a3 (diff)
parent1e08e12d8138b09e6872cb498b723ade9ad71d68 (diff)
Merge pull request #8869 from hercules-ci/fix-issue-8838-pathExists-isDir
Fix #8838, pathExists: isDir when ends with `/ `
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/primops.cc16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 6b99b91e4..e2b1ac4f6 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -1520,15 +1520,25 @@ static RegisterPrimOp primop_storePath({
static void prim_pathExists(EvalState & state, const PosIdx pos, Value * * args, Value & v)
{
+ auto & arg = *args[0];
+
/* We don’t check the path right now, because we don’t want to
throw if the path isn’t allowed, but just return false (and we
can’t just catch the exception here because we still want to
- throw if something in the evaluation of `*args[0]` tries to
+ throw if something in the evaluation of `arg` tries to
access an unauthorized path). */
- auto path = realisePath(state, pos, *args[0], { .checkForPureEval = false });
+ auto path = realisePath(state, pos, arg, { .checkForPureEval = false });
+
+ /* SourcePath doesn't know about trailing slash. */
+ auto mustBeDir = arg.type() == nString && arg.str().ends_with("/");
try {
- v.mkBool(state.checkSourcePath(path).pathExists());
+ auto checked = state.checkSourcePath(path);
+ auto exists = checked.pathExists();
+ if (exists && mustBeDir) {
+ exists = checked.lstat().type == InputAccessor::tDirectory;
+ }
+ v.mkBool(exists);
} catch (SysError & e) {
/* Don't give away info from errors while canonicalising
‘path’ in restricted mode. */