Closed
Description
fs::FileType
should document that is_file()
, is_dir()
, and is_symlink()
are all mutually exclusive. (and that it may also be the case that none of them are true)
Why? Because Path::is_file()
returns true for both files and symlinks to files, and this tends to make me paranoid that a fs::FileType
will share similar characteristics and perhaps claim that both x.is_file()
and x.is_symlink()
. The only way to convince myself that FileType's behavior is indeed sane is to write a little test program---again.
Surely I can't be alone in this.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]`fs::FileType` should document that `is_file`, `is_dir`, and `is_symlink` are mutually exclusive.[/-][+]fs::FileType should document that is_file, is_dir, and is_symlink are mutually exclusive.[/+]retep998 commentedon Feb 19, 2018
Path::is_file()
is callingstat
notlstat
(and equivalent on Windows), so if the path is a symlink, then it returns the results based on what the symlink points to, not the symlink itself. SoPath::is_file()
respects the same mutual exclusivity rules asfs::FileType
.But yes, this ought to be documented, especially given that the mutually exclusive behavior may be surprising to Windows developers.
[-]fs::FileType should document that is_file, is_dir, and is_symlink are mutually exclusive.[/-][+]fs::FileType and Metadata should document that is_file, is_dir, and is_symlink are mutually exclusive.[/+]ExpHP commentedon Feb 19, 2018
Similar goes for
Metadata::{is_file,is_dir}
, which should document that these are always false for aMetadata
obtained by callingsymlink_metadata
on a symlink.retep998 commentedon Feb 19, 2018
Well you can always call
symlink_metadata
on something that is not a symlink, in which caseis_file
oris_dir
could be true.Fix Issue rust-lang#48345, is_file, is_dir, and is_symlink note mutua…
Rollup merge of rust-lang#49076 - bobdavelisafrank:filetype-metadata-…
Rollup merge of rust-lang#49076 - bobdavelisafrank:filetype-metadata-…