1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-26 20:20:58 +01:00

libexpr: Don't use nix::dirOf in prim_dirOf

This gets us back to pre-2.23 behavior of this primop.
Done by inlining the code of `nix::dirOf` from 2.2-maintenance.

(cherry picked from commit a33fccf55a)
This commit is contained in:
Sergei Zimmerman 2025-11-09 18:33:03 +03:00 committed by github-actions[bot]
parent 60c869a673
commit 6f80e44bb4
2 changed files with 8 additions and 3 deletions

View file

@ -1933,8 +1933,13 @@ static void prim_dirOf(EvalState & state, const PosIdx pos, Value ** args, Value
NixStringContext context;
auto path = state.coerceToString(
pos, *args[0], context, "while evaluating the first argument passed to 'builtins.dirOf'", false, false);
auto dir = dirOf(*path);
v.mkString(dir, context);
auto pos = path->rfind('/');
if (pos == path->npos)
v.mkStringMove(".", context);
else if (pos == 0)
v.mkStringMove("/", context);
else
v.mkString(path->substr(0, pos), context);
}
}