Repository navigation
Tracking Issue for fs_try_exists #83186
Description
Activity
- addedC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]
on Mar 16, 2021 Could
try_existsbe added as a free function tostd::fsand then thestd::path::Pathmethod forwards to that? This would be similar to themetadatafunction.My motivation for this is to make it easier for platforms to override the
metadatabased implementation.Reacted by Martin Habovštiak, Raniz Daniel Raneland, Brandon H. Gomes and Acshi HaggenmillerIn the internals discussion @matklad pointed out that
is_file()andis_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?Since #85060, there's now
std::fs::try_existsbut nostd::fs::exists(the method only exists onPath). This is somewhat confusing, especially since the documentation forstd::fs::try_existssays: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 anstd::fs::existsmethod as well for symmetry.Reacted by Jan ŠpačekI think there are a number of options here:
- Add
std::fs::existsas you suggest. - Don't stabilize
std::fs::try_exists. I'd still want there to be some kind offs::try_existsso 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::existsis thatPath::existsis just a convenience wrapper aroundstd::fs::metadata(path).is_ok(). A similar rationale could be applied whenPath::existsis implemented asstd::fs::try_exists(path).unwrap_or(false).
- Add
@roblabla clearly the doc was copied from
Path::try_exist. Would be nice to fix.I've submitted the small PR above which you may want to review.
Reacted by Martin HabovštiakNominating to consider stabilization.
Reacted by Mathspy, Christian Vallentin, Martin Habovštiak and Josh TaylorReacted by Christian Vallentin and Josh Taylor- addedI-libs-api-nominated[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]
on Jun 5, 2022 34 remaining items
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.
Reacted by Sculas- removedto-announceAnnounce this issue on triage meetingAnnounce this issue on triage meeting
on Apr 29, 2024 - added a commit that references this issue
on Jun 22, 2024 - added a commit that references this issue
on Jun 23, 2024 - added 8 commits that reference this issue
on Oct 7, 2024
Feature gate:
#![feature(path_try_exists)]This is a tracking issue for
try_exists()method onstd::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 returnsio::Result<bool>instead of justbool.Public API
Steps / History
try_exists()method tostd::path::Path#81822path_try_exists#85060Path::try_exists()and improve doc #97912Unresolved Questions