mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-09 19:13:26 +03:00
lib.filesystem.pathType: Improve error for non-existent paths
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|
This commit is contained in:
parent
bb6eab0bdb
commit
d064d972f0
2 changed files with 6 additions and 1 deletions
|
@ -22,10 +22,14 @@ in
|
|||
Returns the type of a path: regular (for file), symlink, or directory.
|
||||
*/
|
||||
pathType = path:
|
||||
if ! pathExists path
|
||||
# Fail irrecoverably to mimic the historic behavior of this function and
|
||||
# the new builtins.readFileType
|
||||
then abort "lib.filesystem.pathType: Path ${toString path} does not exist."
|
||||
# The filesystem root is the only path where `dirOf / == /` and
|
||||
# `baseNameOf /` is not valid. We can detect this and directly return
|
||||
# "directory", since we know the filesystem root can't be anything else.
|
||||
if dirOf path == path
|
||||
else if dirOf path == path
|
||||
then "directory"
|
||||
else (readDir (dirOf path)).${baseNameOf path};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue