mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 03:23:29 +03:00
lib.filesystem.pathType: Use new builtins.readFileType if available
Co-Authored-By: Robert Hensing <robert@roberthensing.nl>
This commit is contained in:
parent
84a3d633d6
commit
fcaa2b1097
1 changed files with 15 additions and 11 deletions
|
@ -32,17 +32,21 @@ in
|
||||||
pathType /some/file.nix
|
pathType /some/file.nix
|
||||||
=> "regular"
|
=> "regular"
|
||||||
*/
|
*/
|
||||||
pathType = path:
|
pathType =
|
||||||
if ! pathExists path
|
builtins.readFileType or
|
||||||
# Fail irrecoverably to mimic the historic behavior of this function and
|
# Nix <2.14 compatibility shim
|
||||||
# the new builtins.readFileType
|
(path:
|
||||||
then abort "lib.filesystem.pathType: Path ${toString path} does not exist."
|
if ! pathExists path
|
||||||
# The filesystem root is the only path where `dirOf / == /` and
|
# Fail irrecoverably to mimic the historic behavior of this function and
|
||||||
# `baseNameOf /` is not valid. We can detect this and directly return
|
# the new builtins.readFileType
|
||||||
# "directory", since we know the filesystem root can't be anything else.
|
then abort "lib.filesystem.pathType: Path ${toString path} does not exist."
|
||||||
else if dirOf path == path
|
# The filesystem root is the only path where `dirOf / == /` and
|
||||||
then "directory"
|
# `baseNameOf /` is not valid. We can detect this and directly return
|
||||||
else (readDir (dirOf path)).${baseNameOf path};
|
# "directory", since we know the filesystem root can't be anything else.
|
||||||
|
else if dirOf path == path
|
||||||
|
then "directory"
|
||||||
|
else (readDir (dirOf path)).${baseNameOf path}
|
||||||
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Whether a path exists and is a directory.
|
Whether a path exists and is a directory.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue