Closed
Description
As per rust-lang/rust-clippy#4503, there's a bit of a trap you can fall into if you use is_file()
as a predictor for "can I probably open and read bytes from this thing".
You generally don't want to assert is_file()
for user specified paths, especially if they come from command line arguments, where they might be Unix FIFO File Descriptors.
If for example you were implementing cat
in rust, using is_file()
instead of !is_dir()
would prevent you from reading block devices, character devices, pipes, and more:
S_IFSOCK 0140000 socket
S_IFLNK 0120000 symbolic link
S_IFREG 0100000 regular file
S_IFBLK 0060000 block device
S_IFDIR 0040000 directory
S_IFCHR 0020000 character device
S_IFIFO 0010000 FIFO
And this would break your ability to be composed nicely in Unix flows where patterns like:
diff <( prog_a ) <( prog_b )
Would become broken if diff was a rust program that ensured all its arguments were is_file()