mirror of
https://github.com/NixOS/nix.git
synced 2025-11-10 20:46:01 +01:00
Merge pull request #14515 from NixOS/dirOf-dont-call-std-filesystem
libexpr: Don't use nix::dirOf in prim_dirOf (fix 2.23 regression)
This commit is contained in:
commit
6ebaba50dd
3 changed files with 29 additions and 2 deletions
|
|
@ -2022,8 +2022,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
1
tests/functional/lang/eval-okay-builtins-dirOf.exp
Normal file
1
tests/functional/lang/eval-okay-builtins-dirOf.exp
Normal file
|
|
@ -0,0 +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/./"; }
|
||||
21
tests/functional/lang/eval-okay-builtins-dirOf.nix
Normal file
21
tests/functional/lang/eval-okay-builtins-dirOf.nix
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
stringEmpty = dirOf "";
|
||||
stringNoSep = dirOf "filename";
|
||||
stringSingleDir = dirOf "a/b";
|
||||
stringMultipleSeps = dirOf "a///b";
|
||||
stringRoot = dirOf "/";
|
||||
stringRootSlash = dirOf "//";
|
||||
stringRootSlashSlash = dirOf "///";
|
||||
stringRootA = dirOf "/a";
|
||||
stringWithDot = dirOf "a/b/c/./d";
|
||||
stringWithDotSep2 = dirOf "a/b/c/.//d";
|
||||
stringWithDotDot = dirOf "a/b/c/../d";
|
||||
stringWithDotDotSep2 = dirOf "a/b/c/..//d";
|
||||
stringWithDotAndDotDot = dirOf "a/b/c/.././d";
|
||||
stringWithDotAndDotDotSep2 = dirOf "a/b/c/.././/d";
|
||||
|
||||
pathRoot = dirOf /.;
|
||||
pathDoesntExistRoot = dirOf /totallydoesntexistreally;
|
||||
pathDoesntExistNested1 = dirOf /totallydoesntexistreally/subdir1;
|
||||
pathDoesntExistNested2 = dirOf /totallydoesntexistreally/subdir1/subdir2;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue