Skip to content

Tracking Issue for fs_try_exists #83186

Closed
@Kixunil

Description

@Kixunil
Contributor

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

added
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
on Mar 16, 2021
ChrisDenton

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.

added a commit that references this issue on May 19, 2021

Rollup merge of rust-lang#85060 - ChrisDenton:win-file-exists, r=yaahc

d7c0dd5
added a commit that references this issue on May 21, 2021

Auto merge of rust-lang#85060 - ChrisDenton:win-file-exists, r=yaahc

Kixunil

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?

roblabla

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.

ChrisDenton

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).
Kixunil

Kixunil commented on Feb 1, 2022

@Kixunil
ContributorAuthor

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

62 remaining items

Loading
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-apiRelevant to the library API team, which will review and decide on the PR/issue.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

      Participants

      @joshtriplett@m-ou-se@roblabla@Kixunil@dtolnay

      Issue actions

        Tracking Issue for fs_try_exists · Issue #83186 · rust-lang/rust