diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-04-05 18:42:22 +0200 |
---|---|---|
committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-05-22 14:13:57 +0200 |
commit | fcaa2b1097e46c286b4651f5f2d7653f52ae860b (patch) | |
tree | 77ca39418c2dd96d44a23d799624a296a64f606e | |
parent | 84a3d633d6f3653675d794ef5e8e90bf0cb7c502 (diff) | |
download | nixpkgs-fcaa2b1097e46c286b4651f5f2d7653f52ae860b.tar nixpkgs-fcaa2b1097e46c286b4651f5f2d7653f52ae860b.tar.gz nixpkgs-fcaa2b1097e46c286b4651f5f2d7653f52ae860b.tar.bz2 nixpkgs-fcaa2b1097e46c286b4651f5f2d7653f52ae860b.tar.lz nixpkgs-fcaa2b1097e46c286b4651f5f2d7653f52ae860b.tar.xz nixpkgs-fcaa2b1097e46c286b4651f5f2d7653f52ae860b.tar.zst nixpkgs-fcaa2b1097e46c286b4651f5f2d7653f52ae860b.zip |
lib.filesystem.pathType: Use new builtins.readFileType if available
Co-Authored-By: Robert Hensing <robert@roberthensing.nl>
-rw-r--r-- | lib/filesystem.nix | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/filesystem.nix b/lib/filesystem.nix index 6dfd273b0a5..37b60e4fe11 100644 --- a/lib/filesystem.nix +++ b/lib/filesystem.nix @@ -32,17 +32,21 @@ in pathType /some/file.nix => "regular" */ - 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. - else if dirOf path == path - then "directory" - else (readDir (dirOf path)).${baseNameOf path}; + pathType = + builtins.readFileType or + # Nix <2.14 compatibility shim + (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. + else if dirOf path == path + then "directory" + else (readDir (dirOf path)).${baseNameOf path} + ); /* Whether a path exists and is a directory. |