Skip to content

fs::FileType and Metadata should document that is_file, is_dir, and is_symlink are mutually exclusive. #48345

Closed
@ExpHP

Description

@ExpHP
Contributor

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.

Activity

changed the title [-]`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.[/+] on Feb 19, 2018
retep998

retep998 commented on Feb 19, 2018

@retep998
Member

Path::is_file() is calling stat not lstat (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. So Path::is_file() respects the same mutual exclusivity rules as fs::FileType.

But yes, this ought to be documented, especially given that the mutually exclusive behavior may be surprising to Windows developers.

added
E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
on Feb 19, 2018
changed the title [-]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.[/+] on Feb 19, 2018
ExpHP

ExpHP commented on Feb 19, 2018

@ExpHP
ContributorAuthor

Similar goes for Metadata::{is_file,is_dir}, which should document that these are always false for a Metadata obtained by calling symlink_metadata on a symlink.

retep998

retep998 commented on Feb 19, 2018

@retep998
Member

Well you can always call symlink_metadata on something that is not a symlink, in which case is_file or is_dir could be true.

added
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
on Feb 20, 2018
added a commit that references this issue on Mar 16, 2018

Fix Issue rust-lang#48345, is_file, is_dir, and is_symlink note mutua…

added 2 commits that reference this issue on Mar 24, 2018

Rollup merge of rust-lang#49076 - bobdavelisafrank:filetype-metadata-…

101f7c2

Rollup merge of rust-lang#49076 - bobdavelisafrank:filetype-metadata-…

17d39ed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @retep998@ExpHP@pietroalbini

        Issue actions

          fs::FileType and Metadata should document that is_file, is_dir, and is_symlink are mutually exclusive. · Issue #48345 · rust-lang/rust