primop: add readFileType, optimize readDir

Allows checking directory entry type of a single file/directory.

This was added to optimize the use of `builtins.readDir` on some
filesystems and operating systems which cannot detect this information
using POSIX's `readdir`.

Previously `builtins.readDir` would eagerly use system calls to lookup
these filetypes using other interfaces; this change makes these
operations lazy in the attribute values for each file with application
of `builtins.readFileType`.

(cherry picked from commit 153ee460c5)
This commit is contained in:
Alex Ameen 2023-01-22 13:45:02 -06:00 committed by Eelco Dolstra
parent 374bc3ec8d
commit 62a43a742d

View File

@ -1,2 +1,10 @@
# Release X.Y (202?-??-??)
* A new function `builtins.readFileType` is available. It is similar to
`builtins.readDir` but acts on a single file or directory.
* The `builtins.readDir` function has been optimized when encountering unknown
file types from POSIX's `readdir`. In such cases the type of each file is/was
discovered by making multiple syscalls. This change makes these operations
lazy such that these lookups will only be performed if the attribute is used.
This optimization effects a minority of filesystems and operating systems.