From 5e86e0bf4f5761744bb2e41f8b1012822b35eb14 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 17 Jan 2025 12:28:00 -0500 Subject: [PATCH] fix: ignore permission errors too when looking for user file (#10697) ## Summary The new ARM runners report a permission error: ``` Run uvx twine check wheelhouse/* error: failed to open file `/home/runneradmin/.config/uv/uv.toml`: Permission denied (os error 13) ``` In this PR, a PermissionsError is treated like not finding the file. I reworked the structure just a bit to avoid calling `err.kind()` multiple times. ## Test Plan Added a UNIX only test where I set the permissions of the folder containing the file and try to find it. --------- Signed-off-by: Henry Schreiner --- crates/uv-settings/src/lib.rs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/crates/uv-settings/src/lib.rs b/crates/uv-settings/src/lib.rs index 7d655bda3..31de316c7 100644 --- a/crates/uv-settings/src/lib.rs +++ b/crates/uv-settings/src/lib.rs @@ -49,8 +49,16 @@ impl FilesystemOptions { validate_uv_toml(&file, &options)?; Ok(Some(Self(options))) } - Err(Error::Io(err)) if err.kind() == std::io::ErrorKind::NotFound => Ok(None), - Err(Error::Io(err)) if err.kind() == std::io::ErrorKind::NotADirectory => Ok(None), + Err(Error::Io(err)) + if matches!( + err.kind(), + std::io::ErrorKind::NotFound + | std::io::ErrorKind::NotADirectory + | std::io::ErrorKind::PermissionDenied + ) => + { + Ok(None) + } Err(err) => Err(err), } } @@ -350,6 +358,26 @@ mod test { Ok(()) } + #[test] + #[cfg(unix)] + fn test_locate_system_config_xdg_unix_permissions() -> Result<(), FixtureError> { + let context = assert_fs::TempDir::new()?; + let config = context.child("uv").child("uv.toml"); + config.write_str("")?; + fs_err::set_permissions( + &context, + std::os::unix::fs::PermissionsExt::from_mode(0o000), + ) + .unwrap(); + + assert_eq!( + locate_system_config_xdg(Some(context.to_str().unwrap())), + None + ); + + Ok(()) + } + #[test] #[cfg(windows)] fn test_windows_config() -> Result<(), FixtureError> {