fix: ignore permission errors too when looking for user file (#10697)

<!--
Thank you for contributing to uv! To help us out with reviewing, please
consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

<!-- What's the purpose of the change? What does it do, and why? -->

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

<!-- How was it tested? -->

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 <henryschreineriii@gmail.com>
This commit is contained in:
Henry Schreiner 2025-01-17 12:28:00 -05:00 committed by GitHub
parent e02a7bb75d
commit 5e86e0bf4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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> {