Skip to content

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

Open
PaulDance wants to merge 1 commit into
rust-lang:mainfrom
PaulDance:patches/fix-win7-set_get_permissions_nofollows
Open

Fix(lib/fs/tests): Avoid permission denials when cleaning up TempDirs in set_get_permissions_nofollows*#160281
PaulDance wants to merge 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

… 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>
@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
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 S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

3 participants