Fix(lib/fs/tests): Avoid permission denials when cleaning up TempDirs in set_get_permissions_nofollows* - #160281
Conversation
|
r? @clarfonthey rustbot has assigned @clarfonthey. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Hmm, I honestly would be fine updating the test to do this on all platforms just as a safety measure, since nothing about this change is necessarily windows-specific. Looking at our target policy, only Windows 10+ is supported, but I do think it's fine to ensure the tests pass in this one case just to extend the support. @rustbot ping windows |
|
Hey Windows Group! This issue has been identified as a good "Windows candidate". cc @albertlarsan68 @arlosi @ChrisDenton @danielframpton @dpaoliello @gdr-at-ms @kennykerr @luqmana @nico-abram @retep998 @sivadeilra @wesleywiser |
| // Reset the read-only bit under Windows: avoids the `TempDir::drop` from | ||
| // crashing on a permission denial when trying to delete the file that has it. |
There was a problem hiding this comment.
Would add a comment that currently, this has only been noticed for Windows 7 (which is EOL), but that it's fine to add this out of an abundance of caution.
(Ditto for the other comment.)
Would be particularly interested to ensure that this passes all the tests on the other platforms that were relevant for this change, since I can't imagine that happening, but it's worth trying anyway.
You'd want to move the block specifically into the cfg_select! block, though, to only do this on platforms where we explicitly trust that this operation is supported.
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
|
@clarfonthey Windows 7 is a tier 3 target. We don't test it in CI but people supporting the platform should fix any problems (as is done here). As to the issue itself, we do actually document this:
|
… in `set_get_permissions_nofollows*`
At least under Windows 7, the `set_get_permissions_nofollows` and
`set_get_permissions_nofollows_symlink` FS tests currently fail on:
```
---- fs::tests::set_get_permissions_nofollows stdout ----
thread 'fs::tests::set_get_permissions_nofollows' (2308) panicked at library/std/src/test_helpers.rs:53:20:
called `Result::unwrap()` on an `Err` value: Os { code: 5, kind: PermissionDenied, message: "Access is denied." }
---- fs::tests::set_get_permissions_nofollows stdout end ----
---- fs::tests::set_get_permissions_nofollows_symlink stdout ----
thread 'fs::tests::set_get_permissions_nofollows_symlink' (1108) panicked at library/std/src/test_helpers.rs:53:20:
called `Result::unwrap()` on an `Err` value: Os { code: 5, kind: PermissionDenied, message: "Access is denied." }
---- fs::tests::set_get_permissions_nofollows_symlink stdout end ----
```
The panic clearly occurs in `TempDir::drop` that calls `fs::remove_dir_all`.
This is consistent with the fact that `FILE_ATTRIBUTE_READONLY` is set
on the file:
> Applications can read the file, but cannot write to it or delete it.
from [the attribute's documentation].
This therefore fixes these tests by resetting the attribute before
letting the drop guard run.
[the attribute's documentation]: https://learn.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants
Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
41f11ee to
bcc5501
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
I moved the block to the @rustbot ready |
|
Probably should have tried harder to check that Windows 7 was a separate tier; I just assumed that they would all fall under Windows but… yeah. Anyway, thank you for the change, and assuming that it works: @bors r+ rollup |
…uwer Rollup of 8 pull requests Successful merges: - #160262 (Library lock file maintenance) - #158548 (Move `std::io::copy` to `alloc::io`) - #158814 (Produce an error when `#[inline]` and `#[rust_force_inline]` are used together) - #160025 (Fix an edge case with `StepBy::nth` on non-fused iterators) - #160271 (Resolver: Introduce `CmRef` which has a speclative borrow variant for `CmRefCell`) - #160281 (Fix(lib/fs/tests): Avoid permission denials when cleaning up TempDirs in `set_get_permissions_nofollows*`) - #160325 (tidy: Check `proc_macro_deps.rs` by reading it, not by including it) - #160334 (Add regression test for unused_allocation on boxed comparison)
|
Thanks! |
At least under Windows 7, the
set_get_permissions_nofollowsandset_get_permissions_nofollows_symlinkFS tests currently fail on:The panic clearly occurs in
TempDir::dropthat callsfs::remove_dir_all. This is consistent with the fact thatFILE_ATTRIBUTE_READONLYis set on the file:from the attribute's documentation.
This therefore fixes these tests by resetting the attribute before letting the drop guard run.
cc #141607 @roblabla
@rustbot label T-libs A-io O-windows-7