From f22021fe81f05d6f4dcce5ca962f5e5384c1d602 Mon Sep 17 00:00:00 2001 From: Paul Mabileau Date: Fri, 16 May 2025 22:49:00 +0200 Subject: [PATCH] Test(fs): Fix test_eq_windows_file_type for Windows 7 Would otherwise fail on: ``` thread 'fs::tests::test_eq_windows_file_type' 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." } ``` This came from the read-only attribute set on the test file. In order to fix this, instead of simply disabling the test, the attribute is reset before the test's end so it may still run successfully. Signed-off-by: Paul Mabileau --- library/std/src/fs/tests.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs index c81a5ff4d96e6..efc8c04233f3a 100644 --- a/library/std/src/fs/tests.rs +++ b/library/std/src/fs/tests.rs @@ -1760,8 +1760,14 @@ fn test_eq_windows_file_type() { // Change the readonly attribute of one file. let mut perms = file1.metadata().unwrap().permissions(); perms.set_readonly(true); - file1.set_permissions(perms).unwrap(); + file1.set_permissions(perms.clone()).unwrap(); assert_eq!(file1.metadata().unwrap().file_type(), file2.metadata().unwrap().file_type()); + + // Reset the attribute before the `TmpDir`'s drop that removes the + // associated directory, which fails with a `PermissionDenied` error when + // running under Windows 7. + perms.set_readonly(false); + file1.set_permissions(perms).unwrap(); } /// Regression test for https://github.com/rust-lang/rust/issues/50619.