Skip to content

Commit 6ebaba5

Browse files
authored
Merge pull request #14515 from NixOS/dirOf-dont-call-std-filesystem
libexpr: Don't use nix::dirOf in prim_dirOf (fix 2.23 regression)
2 parents 18941cb + a33fccf commit 6ebaba5

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/libexpr/primops.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,8 +2022,13 @@ static void prim_dirOf(EvalState & state, const PosIdx pos, Value ** args, Value
20222022
NixStringContext context;
20232023
auto path = state.coerceToString(
20242024
pos, *args[0], context, "while evaluating the first argument passed to 'builtins.dirOf'", false, false);
2025-
auto dir = dirOf(*path);
2026-
v.mkString(dir, context);
2025+
auto pos = path->rfind('/');
2026+
if (pos == path->npos)
2027+
v.mkStringMove(".", context);
2028+
else if (pos == 0)
2029+
v.mkStringMove("/", context);
2030+
else
2031+
v.mkString(path->substr(0, pos), context);
20272032
}
20282033
}
20292034

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ pathDoesntExistNested1 = /totallydoesntexistreally; pathDoesntExistNested2 = /totallydoesntexistreally/subdir1; pathDoesntExistRoot = /; pathRoot = /; stringEmpty = "."; stringMultipleSeps = "a//"; stringNoSep = "."; stringRoot = "/"; stringRootA = "/"; stringRootSlash = "/"; stringRootSlashSlash = "//"; stringSingleDir = "a"; stringWithDot = "a/b/c/."; stringWithDotAndDotDot = "a/b/c/../."; stringWithDotAndDotDotSep2 = "a/b/c/.././"; stringWithDotDot = "a/b/c/.."; stringWithDotDotSep2 = "a/b/c/../"; stringWithDotSep2 = "a/b/c/./"; }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
stringEmpty = dirOf "";
3+
stringNoSep = dirOf "filename";
4+
stringSingleDir = dirOf "a/b";
5+
stringMultipleSeps = dirOf "a///b";
6+
stringRoot = dirOf "/";
7+
stringRootSlash = dirOf "//";
8+
stringRootSlashSlash = dirOf "///";
9+
stringRootA = dirOf "/a";
10+
stringWithDot = dirOf "a/b/c/./d";
11+
stringWithDotSep2 = dirOf "a/b/c/.//d";
12+
stringWithDotDot = dirOf "a/b/c/../d";
13+
stringWithDotDotSep2 = dirOf "a/b/c/..//d";
14+
stringWithDotAndDotDot = dirOf "a/b/c/.././d";
15+
stringWithDotAndDotDotSep2 = dirOf "a/b/c/.././/d";
16+
17+
pathRoot = dirOf /.;
18+
pathDoesntExistRoot = dirOf /totallydoesntexistreally;
19+
pathDoesntExistNested1 = dirOf /totallydoesntexistreally/subdir1;
20+
pathDoesntExistNested2 = dirOf /totallydoesntexistreally/subdir1/subdir2;
21+
}

0 commit comments

Comments
 (0)