pathType
lib.filesystem.pathType
Primop
Docs pulled from | This Revision | 14 minutes ago
Takes 1 arguments
p
The type of a path. The path needs to exist and be accessible. The result is either "directory" for a directory, "regular" for a regular file, "symlink" for a symlink, or "unknown" for anything else.
Inputs
- path
-
The path to query
Type
pathType :: Path -> String
Examples
lib.filesystem.pathType
usage example
pathType /.
=> "directory"
pathType /some/file.nix
=> "regular"
Noogle detected
Implementation
This function is implemented in c++ and is part of the native nix runtime.
Implementation
The following is the current implementation of this function.
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}
);