Skip to content

Tracking Issue for fs_try_exists #83186

Description

@Kixunil

Feature gate: #![feature(path_try_exists)]

This is a tracking issue for try_exists() method on std::path::Path.

This method is similar to exists() method except it does not silently ignore errors that made it impossible to find out if the path actually exists (e.g. lack of permission on parent dir). Thus it naturally returns io::Result<bool> instead of just bool.

Public API

mod fs {
    pub fn try_exists<P: AsRef<Path>>(path: P) -> Result<bool>;
}

impl Path {
    #[stable(since = "1.63.0")]
    pub fn try_exists(&self) -> io::Result<bool>;
}

Steps / History

Unresolved Questions

  • None yet.

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    T-libs-api[DEPRECATED; DO NOT USE]
    on Mar 16, 2021
  2. ChrisDenton commented on Mar 17, 2021

    @ChrisDenton
    Member

    Could try_exists be added as a free function to std::fs and then the std::path::Path method forwards to that? This would be similar to the metadata function.

    My motivation for this is to make it easier for platforms to override the metadata based implementation.

  3. added a commit that references this issue on May 19, 2021
  4. added a commit that references this issue on May 21, 2021
  5. Kixunil commented on Aug 21, 2021

    @Kixunil
    ContributorAuthor

    In the internals discussion @matklad pointed out that is_file() and is_dir() have same issue. I believe it may be even worse in their case. I wonder would it be reasonable to add those method within the scope of this feature or as a separate change?

  6. roblabla commented on Feb 1, 2022

    @roblabla
    Contributor

    Since #85060, there's now std::fs::try_exists but no std::fs::exists (the method only exists on Path). This is somewhat confusing, especially since the documentation for std::fs::try_exists says:

    As opposed to the exists() method, this one doesn’t silently ignore errors unrelated to the path not existing.

    Without linking the appropriate exists method.

    I think if we're going to have an std::fs::try_exists, we'll want to make an std::fs::exists method as well for symmetry.

  7. ChrisDenton commented on Feb 1, 2022

    @ChrisDenton
    Member

    I think there are a number of options here:

    • Add std::fs::exists as you suggest.
    • Don't stabilize std::fs::try_exists. I'd still want there to be some kind of fs::try_exists so that different platforms can specialize the implementation. But that can be purely internal to the standard library.
    • Keep the current API but improve the docs. The original rationale for not having an std::fs::exists is that Path::exists is just a convenience wrapper around std::fs::metadata(path).is_ok(). A similar rationale could be applied when Path::exists is implemented as std::fs::try_exists(path).unwrap_or(false).
  8. Kixunil commented on Feb 1, 2022

    @Kixunil
    ContributorAuthor

    @roblabla clearly the doc was copied from Path::try_exist. Would be nice to fix.

  9. ChrisDenton commented on Feb 1, 2022

    @ChrisDenton
    Member

    I've submitted the small PR above which you may want to review.

  10. added 2 commits that reference this issue on Feb 4, 2022
  11. joshtriplett commented on Jun 5, 2022

    @joshtriplett
    Member

    Nominating to consider stabilization.

  12. 34 remaining items

  13. rfcbot commented on Apr 16, 2024

    @rfcbot

    The final comment period, with a disposition to merge, as per the review above, is now complete.

    As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

    This will be merged soon.

  14. added a commit that references this issue on Jun 11, 2024
  15. added a commit that references this issue on Jun 22, 2024
  16. added a commit that references this issue on Jun 22, 2024
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

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-api[DEPRECATED; DO NOT USE]disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions