Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize Path::try_exists() and improve doc #97912

Merged
merged 1 commit into from
Jun 20, 2022

Conversation

Kixunil
Copy link
Contributor

@Kixunil Kixunil commented Jun 9, 2022

This stabilizes the Path::try_exists() method which returns
Result<bool, io::Error> instead of bool allowing handling of errors
unrelated to the file not existing. (e.g permission errors)

Along with the stabilization it also:

  • Warns that the exists() method is error-prone and suggests to use
    the newly stabilized one.
  • Suggests it instead of metadata() to handle errors.
  • Mentions TOCTOU bugs to avoid false assumption that try_exists() is
    completely safe fixed version of exists().
  • Renames the feature of still-unstable std::fs::try_exists() to
    fs_try_exists to avoid name conflict.

The tracking issue #83186 remains open to track fs_try_exists.

@rust-highfive
Copy link
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Jun 9, 2022
@rust-highfive
Copy link
Collaborator

r? @m-ou-se

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 9, 2022
@Kixunil
Copy link
Contributor Author

Kixunil commented Jun 9, 2022

@rustbot label +T-libs-api -T-libs

@rustbot rustbot added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 9, 2022
@m-ou-se
Copy link
Member

m-ou-se commented Jun 9, 2022

@rfcbot merge

@rfcbot
Copy link

rfcbot commented Jun 9, 2022

Team member @m-ou-se has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Jun 9, 2022
@Kixunil Kixunil force-pushed the stabilize_path_try_exists branch from cd374ae to 9f97ad9 Compare June 9, 2022 11:13
@rust-log-analyzer

This comment has been minimized.

@Kixunil Kixunil force-pushed the stabilize_path_try_exists branch from 9f97ad9 to dfd0b80 Compare June 9, 2022 13:23
@Kixunil
Copy link
Contributor Author

Kixunil commented Jun 9, 2022

Hmm:

tidy error: binary checked into source: /checkout/compiler/rustc_error_messages/src/lib.rs

I don't understand this. git show HEAD doesn't show anything binary that I had accidentally added. Can someone help, please?

@klensy
Copy link
Contributor

klensy commented Jun 9, 2022

Looks like you changed metadata of file, like chmod ..., revert it.

fn is_executable(path: &Path) -> std::io::Result<bool> {
Ok(path.metadata()?.mode() & 0o111 != 0)
}

Yes, you can see file permissions change in git diff or in github diff compiler/rustc_error_messages/src/lib.rs

@Kixunil Kixunil force-pushed the stabilize_path_try_exists branch from dfd0b80 to 1651b55 Compare June 9, 2022 17:20
@Kixunil
Copy link
Contributor Author

Kixunil commented Jun 9, 2022

@klensy thanks! (I have a vim script that sets executable bit for files beginning with #!. :))

@rust-log-analyzer

This comment has been minimized.

@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Jun 9, 2022
@rfcbot
Copy link

rfcbot commented Jun 9, 2022

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Jun 9, 2022
@Kixunil Kixunil force-pushed the stabilize_path_try_exists branch from 1651b55 to 83a0313 Compare June 9, 2022 21:15
library/std/src/path.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Jun 14, 2022

☔ The latest upstream changes (presumably #98091) made this pull request unmergeable. Please resolve the merge conflicts.

This stabilizes the `Path::try_exists()` method which returns
`Result<bool, io::Error>` instead of `bool` allowing handling of errors
unrelated to the file not existing. (e.g permission errors)

Along with the stabilization it also:

* Warns that the `exists()` method is error-prone and suggests to use
  the newly stabilized one.
* Suggests it instead of `metadata()` to handle errors.
* Mentions TOCTOU bugs to avoid false assumption that `try_exists()` is
  completely safe fixed version of `exists()`.
* Renames the feature of still-unstable `std::fs::try_exists()` to
  `fs_try_exists` to avoid name conflict.

The tracking issue rust-lang#83186 remains open to track `fs_try_exists`.
@rfcbot rfcbot added the finished-final-comment-period The final comment period is finished for this PR / Issue. label Jun 19, 2022
@rfcbot rfcbot added to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Jun 19, 2022
@rfcbot
Copy link

rfcbot commented Jun 19, 2022

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.

@dtolnay
Copy link
Member

dtolnay commented Jun 19, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Jun 19, 2022

📌 Commit 5608707 has been approved by dtolnay

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 19, 2022
@dtolnay dtolnay assigned dtolnay and unassigned m-ou-se Jun 19, 2022
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jun 19, 2022
…r=dtolnay

Stabilize `Path::try_exists()` and improve doc

This stabilizes the `Path::try_exists()` method which returns
`Result<bool, io::Error>` instead of `bool` allowing handling of errors
unrelated to the file not existing. (e.g permission errors)

Along with the stabilization it also:

* Warns that the `exists()` method is error-prone and suggests to use
  the newly stabilized one.
* Suggests it instead of `metadata()` to handle errors.
* Mentions TOCTOU bugs to avoid false assumption that `try_exists()` is
  completely safe fixed version of `exists()`.
* Renames the feature of still-unstable `std::fs::try_exists()` to
  `fs_try_exists` to avoid name conflict.

The tracking issue rust-lang#83186 remains open to track `fs_try_exists`.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 20, 2022
Rollup of 4 pull requests

Successful merges:

 - rust-lang#95534 (Add `core::mem::copy` to complement `core::mem::drop`.)
 - rust-lang#97912 (Stabilize `Path::try_exists()` and improve doc)
 - rust-lang#98225 (Make debug_triple depend on target json file content rather than file path)
 - rust-lang#98257 (Fix typos in `IntoFuture` docs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 77316a4 into rust-lang:master Jun 20, 2022
@bors
Copy link
Contributor

bors commented Jun 20, 2022

⌛ Testing commit 5608707 with merge 17c6bde...

@rustbot rustbot added this to the 1.63.0 milestone Jun 20, 2022
@Kixunil Kixunil deleted the stabilize_path_try_exists branch June 20, 2022 06:53
@JohnTitor JohnTitor added the relnotes Marks issues that should be documented in the release notes of the next release. label Jun 21, 2022
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.