Improvements to pathType, pathIsDirectory and pathIsRegularFile#224834
Improvements to pathType, pathIsDirectory and pathIsRegularFile#224834roberth merged 8 commits intoNixOS:masterfrom
Conversation
These functions only work with the filesystem, they don't import anything as sources
|
Something I don't want to go into for this PR, but maybe in the future: The semantics of
We should consider having alternate functions with cleaner semantics in the future:
These laws would then hold:
Unfortunately the implementation of these functions would have to be a bit hacky (throwing for non-existent paths not implemented here): {
isDirectory = path: builtins.pathExists "${toString path}/";
isFile = path: ! builtins.pathExists "${toString path}/";
}This uses the fact that:
To implement these I'd propose adding more builtins, either:
|
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
That's good. How about this?
|
lib/filesystem.nix
Outdated
There was a problem hiding this comment.
2.14 was not a success, but 2.15 is out now.
This can be upgraded to a polyfill now.
There was a problem hiding this comment.
Done. Also take a look at NixOS/nix#7447 (comment)
85f7a5c to
7c57a47
Compare
|
@roberth I'd probably go for |
7c57a47 to
e9cc2dc
Compare
roberth
left a comment
There was a problem hiding this comment.
Some minor suggestions and a less minor idea to improve the developer experience. I'd add the comments myself, but it's better to share the idea.
Co-Authored-By: Robert Hensing <[email protected]>
Co-Authored-By: Robert Hensing <[email protected]>
Previously this function couldn't handle / being passed, it would throw
an error:
error: attribute '' missing
at nixpkgs/lib/filesystem.nix:24:20:
23| */
24| pathType = path: (readDir (dirOf path)).${baseNameOf path};
| ^
25|
Consequently this also fixes the
lib.filesystem.{pathIsDirectory,pathIsRegularFile} functions.
Previously it would fail with
error: attribute 'nonexistent' missing
at nixpkgs/lib/filesystem.nix:29:10:
28| if dirOf path == path then "directory"
29| else (readDir (dirOf path)).${baseNameOf path};
| ^
30|
Co-Authored-By: Robert Hensing <[email protected]>
Co-Authored-By: Robert Hensing <[email protected]>
e9cc2dc to
378bf1a
Compare
|
Successfully created backport PR for |
|
Git push to origin failed for release-23.05 with exitcode 1 |
Description of changes
This is related to the path library effort.
Improves the
lib.sources.pathType,lib.sources.pathIsDirectoryandlib.sources.pathIsRegularFilefunctions, each of which is a single commit:lib.filesystem, since they only work with the filesystem, they don't import any sources. The functions are still available inlib.sources, but will be deprecated after the next release./is passed. Previously they threw an unintuitive error:pathTypeerror message for invalid paths. Previously this was the error:pathTypecan get replaced with the newbuiltins.readFileTypeonce Nix 2.14 is releasedThis work is sponsored by Antithesis ✨
Things done
nix-build doc)lib/tests/filesystem.shon its ownnix-build lib/tests/release.nix