Do not error if the `CACHEDIR.TAG` file exists but cannot be written to (#7550)

Attempting to address the error in
https://github.com/astral-sh/uv/issues/7434 — it seems overkill to fail
if the file exists but isn't writable.
This commit is contained in:
Zanie Blue 2024-09-19 09:39:59 -05:00 committed by GitHub
parent 99d57ca80e
commit 5206a33e78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 1 deletions

View File

@ -32,9 +32,13 @@ pub fn add_tag<P: AsRef<path::Path>>(directory: P) -> io::Result<()> {
/// Will return an error if The tag file doesn't exist and can't be created for any reason
/// (the `directory` doesn't exist, permission error, can't write to the file etc.).
pub fn ensure_tag<P: AsRef<path::Path>>(directory: P) -> io::Result<()> {
match add_tag(directory) {
match add_tag(&directory) {
Err(e) => match e.kind() {
io::ErrorKind::AlreadyExists => Ok(()),
// If it exists, but we can't write to it for some reason don't fail
io::ErrorKind::PermissionDenied if directory.as_ref().join("CACHEDIR.TAG").exists() => {
Ok(())
}
_ => Err(e),
},
other => other,