Skip to content

Fix(lib/fs/tests): Avoid permission denials when cleaning up TempDirs in set_get_permissions_nofollows* - #160281

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
PaulDance:patches/fix-win7-set_get_permissions_nofollows
Aug 1, 2026
Merged

Fix(lib/fs/tests): Avoid permission denials when cleaning up TempDirs in set_get_permissions_nofollows*#160281
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
PaulDance:patches/fix-win7-set_get_permissions_nofollows

Conversation

@PaulDance

@PaulDance PaulDance commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

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.

cc #141607 @roblabla

@rustbot label T-libs A-io O-windows-7

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` O-windows Operating system: Windows labels Jul 31, 2026
@PaulDance
PaulDance marked this pull request as ready for review July 31, 2026 15:45
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 31, 2026
@rustbot

rustbot commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

r? @clarfonthey

rustbot has assigned @clarfonthey.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 13 candidates
  • Random selection from 7 candidates

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 31, 2026
@clarfonthey

Copy link
Copy Markdown
Contributor

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
In case anyone wants to comment on Windows 7-specific hacks, or support before Windows 10 in general.

@rustbot

rustbot commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Hey Windows Group! This issue has been identified as a good "Windows candidate".
In case it's useful, here are some instructions for tackling these sorts of
issues. Maybe take a look?
Thanks! <3

cc @albertlarsan68 @arlosi @ChrisDenton @danielframpton @dpaoliello @gdr-at-ms @kennykerr @luqmana @nico-abram @retep998 @sivadeilra @wesleywiser

Comment thread library/std/src/fs/tests.rs Outdated
Comment on lines +639 to +640
// 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.

@clarfonthey clarfonthey Aug 1, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

View changes since the review

@clarfonthey

Copy link
Copy Markdown
Contributor

@rustbot author

@rustbot rustbot 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-review Status: Awaiting review from the assignee but also interested parties. labels Aug 1, 2026
@rustbot

rustbot commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@ChrisDenton

ChrisDenton commented Aug 1, 2026

Copy link
Copy Markdown
Member

@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 Windows 7 and earlier this attribute prevents deleting empty directories. It does not prevent modifying the directory contents. On later versions of Windows this attribute is ignored for directories.

… 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>
@PaulDance
PaulDance force-pushed the patches/fix-win7-set_get_permissions_nofollows branch from 41f11ee to bcc5501 Compare August 1, 2026 14:32
@rustbot

rustbot commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

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.

@rustbot rustbot added the O-windows-7 OS: Windows 7 or Windows Server 2008 R2 or etc. label Aug 1, 2026
@PaulDance

Copy link
Copy Markdown
Contributor Author

I moved the block to the cfg_select!. I also made it Win7-specific as this is more correct. If other platforms fail, then it would be surprising and there would be something to investigate I'd say.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 1, 2026
@clarfonthey

Copy link
Copy Markdown
Contributor

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

@rust-bors

rust-bors Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

📌 Commit bcc5501 has been approved by clarfonthey

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Aug 1, 2026
rust-bors Bot pushed a commit that referenced this pull request Aug 1, 2026
…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)
@rust-bors
rust-bors Bot merged commit 68485b5 into rust-lang:main Aug 1, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Aug 1, 2026
@PaulDance
PaulDance deleted the patches/fix-win7-set_get_permissions_nofollows branch August 1, 2026 21:07
@PaulDance

Copy link
Copy Markdown
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` O-windows Operating system: Windows O-windows-7 OS: Windows 7 or Windows Server 2008 R2 or etc. 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.

4 participants