@@ -110,7 +110,7 @@ StringMap EvalState::realiseContext(const NixStringContext & context)
110110 return res;
111111}
112112
113- static SourcePath realisePath (EvalState & state, const PosIdx pos, Value & v)
113+ static SourcePath realisePath (EvalState & state, const PosIdx pos, Value & v, bool resolveSymlinks = true )
114114{
115115 NixStringContext context;
116116
@@ -120,9 +120,9 @@ static SourcePath realisePath(EvalState & state, const PosIdx pos, Value & v)
120120 if (!context.empty () && path.accessor == state.rootFS ) {
121121 auto rewrites = state.realiseContext (context);
122122 auto realPath = state.toRealPath (rewriteStrings (path.path .abs (), rewrites), context);
123- return {path.accessor , CanonPath (realPath)};
124- } else
125- return path;
123+ path = {path.accessor , CanonPath (realPath)};
124+ }
125+ return resolveSymlinks ? path. resolveSymlinks () : path;
126126 } catch (Error & e) {
127127 e.addTrace (state.positions [pos], " while realising the context of path '%s'" , path);
128128 throw ;
@@ -162,7 +162,7 @@ static void mkOutputString(
162162 argument. */
163163static void import (EvalState & state, const PosIdx pos, Value & vPath, Value * vScope, Value & v)
164164{
165- auto path = realisePath (state, pos, vPath);
165+ auto path = realisePath (state, pos, vPath, false );
166166 auto path2 = path.path .abs ();
167167
168168 // FIXME
@@ -1525,16 +1525,16 @@ static RegisterPrimOp primop_storePath({
15251525
15261526static void prim_pathExists (EvalState & state, const PosIdx pos, Value * * args, Value & v)
15271527{
1528- auto & arg = *args[0 ];
1528+ try {
1529+ auto & arg = *args[0 ];
15291530
1530- auto path = realisePath (state, pos, arg);
1531+ auto path = realisePath (state, pos, arg);
15311532
1532- /* SourcePath doesn't know about trailing slash. */
1533- auto mustBeDir = arg.type () == nString
1534- && (arg.string_view ().ends_with (" /" )
1535- || arg.string_view ().ends_with (" /." ));
1533+ /* SourcePath doesn't know about trailing slash. */
1534+ auto mustBeDir = arg.type () == nString
1535+ && (arg.string_view ().ends_with (" /" )
1536+ || arg.string_view ().ends_with (" /." ));
15361537
1537- try {
15381538 auto st = path.maybeLstat ();
15391539 auto exists = st && (!mustBeDir || st->type == SourceAccessor::tDirectory);
15401540 v.mkBool (exists);
@@ -1771,7 +1771,7 @@ static std::string_view fileTypeToString(InputAccessor::Type type)
17711771
17721772static void prim_readFileType (EvalState & state, const PosIdx pos, Value * * args, Value & v)
17731773{
1774- auto path = realisePath (state, pos, *args[0 ]);
1774+ auto path = realisePath (state, pos, *args[0 ], false );
17751775 /* Retrieve the directory entry type and stringize it. */
17761776 v.mkString (fileTypeToString (path.lstat ().type ));
17771777}
0 commit comments