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

Windows: Use FindFirstFileW for getting the metadata of locked system files #98916

Merged
merged 5 commits into from
Jul 20, 2022

Conversation

ChrisDenton
Copy link
Member

Fixes #96980

Usually opening a file handle with access set to metadata only will always succeed, even if the file is locked. However some special system files, such as C:\hiberfil.sys, are locked by the system in a way that denies even that. So as a fallback we try reading the cached metadata from the directory.

Note that the test is a bit iffy. I don't know if hiberfil.sys actually exists in the CI.

r? rust-lang/libs

Usually opening a file handle with access set to metadata only will always succeed, even if the file is locked. However some special system files, such as `C:\hiberfil.sys`, are locked by the system in a way that denies even that. So as a fallback we try reading the cached metadata from the directory.
@rustbot
Copy link
Collaborator

rustbot commented Jul 5, 2022

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 Jul 5, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 5, 2022
library/std/src/fs/tests.rs Outdated Show resolved Hide resolved
@strega-nil-ms
Copy link

strega-nil-ms commented Jul 8, 2022

This is, as far as I can tell, equivalent to the code in the Microsoft STL: https://github.com/microsoft/STL/blob/062002644137095c606f0a5a11d04f0278e8632e/stl/src/filesystem.cpp#L794

(and so is likely to be correct)

Copy link
Member

@thomcc thomcc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it took so long to get to this. This looks good to me.

@thomcc
Copy link
Member

thomcc commented Jul 17, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Jul 17, 2022

📌 Commit 5f5bcb3 has been approved by thomcc

It is now in the queue for this repository.

@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 Jul 17, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jul 18, 2022
Windows: Use `FindFirstFileW` for getting the metadata of locked system files

Fixes rust-lang#96980

Usually opening a file handle with access set to metadata only will always succeed, even if the file is locked. However some special system files, such as `C:\hiberfil.sys`, are locked by the system in a way that denies even that. So as a fallback we try reading the cached metadata from the directory.

Note that the test is a bit iffy. I don't know if `hiberfil.sys` actually exists in the CI.

r? rust-lang/libs
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jul 18, 2022
Windows: Use `FindFirstFileW` for getting the metadata of locked system files

Fixes rust-lang#96980

Usually opening a file handle with access set to metadata only will always succeed, even if the file is locked. However some special system files, such as `C:\hiberfil.sys`, are locked by the system in a way that denies even that. So as a fallback we try reading the cached metadata from the directory.

Note that the test is a bit iffy. I don't know if `hiberfil.sys` actually exists in the CI.

r? rust-lang/libs
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jul 18, 2022
Windows: Use `FindFirstFileW` for getting the metadata of locked system files

Fixes rust-lang#96980

Usually opening a file handle with access set to metadata only will always succeed, even if the file is locked. However some special system files, such as `C:\hiberfil.sys`, are locked by the system in a way that denies even that. So as a fallback we try reading the cached metadata from the directory.

Note that the test is a bit iffy. I don't know if `hiberfil.sys` actually exists in the CI.

r? rust-lang/libs
@ChrisDenton
Copy link
Member Author

@bors r- failed in rollup

Oh, I was afraid of this. hiberfil.sys doesn't exist in CI. Hm, maybe we could keep the test but mark it as ignore? Admittedly it not running in CI very much limits its utility but at least it can be run locally.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 18, 2022
@thomcc
Copy link
Member

thomcc commented Jul 18, 2022

Oof, I thought about marking it as rollup=never for that reason (I guess doing a try run would have been more prudent...)

Marking the test as ignore makes sense to me.

The file it's testing does not exist in the CI environment.
@thomcc
Copy link
Member

thomcc commented Jul 18, 2022

It seems a bit goofy to do a try run now that the test is ignored, so I'll just reapprove.

@bors r+

@bors
Copy link
Contributor

bors commented Jul 18, 2022

📌 Commit eee8ca9 has been approved by thomcc

It is now in the queue for this repository.

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 18, 2022
@Dylan-DPC
Copy link
Member

failed in rollup

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 18, 2022
@ChrisDenton
Copy link
Member Author

Sorry, we already noticed that and addressed the issue.

@bors r=thomcc

@bors
Copy link
Contributor

bors commented Jul 18, 2022

📌 Commit eee8ca9 has been approved by thomcc

It is now in the queue for this repository.

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 18, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 20, 2022
Rollup of 5 pull requests

Successful merges:

 - rust-lang#98784 (Suggest returning local on "expected `ty`, found `()`" due to expr-less block)
 - rust-lang#98916 (Windows: Use `FindFirstFileW` for getting the metadata of locked system files)
 - rust-lang#99433 (Erase regions before comparing signatures of foreign fns.)
 - rust-lang#99452 (int_macros was only using to_xe_bytes_doc and not from_xe_bytes_doc)
 - rust-lang#99481 (Add regression test for rust-lang#71547)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 8039567 into rust-lang:master Jul 20, 2022
@rustbot rustbot added this to the 1.64.0 milestone Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[fs] Path::new(r#"C:\hiberfil.sys"#).exists() returns false, despite the file existing
8 participants