mirror of https://github.com/astral-sh/ruff
Make cache-write failures non-fatal (#12302)
## Summary Closes https://github.com/astral-sh/ruff/issues/12284.
This commit is contained in:
parent
aa5c53b38b
commit
e58713e2ac
|
|
@ -180,12 +180,24 @@ impl Cache {
|
|||
.write_all(&serialized)
|
||||
.context("Failed to write serialized cache to temporary file.")?;
|
||||
|
||||
temp_file.persist(&self.path).with_context(|| {
|
||||
if let Err(err) = temp_file.persist(&self.path) {
|
||||
// On Windows, writing to the cache file can fail if the file is still open (e.g., if
|
||||
// the user is running Ruff from multiple processes over the same directory).
|
||||
if cfg!(windows) && err.error.kind() == io::ErrorKind::PermissionDenied {
|
||||
warn_user!(
|
||||
"Failed to write cache file '{}': {}",
|
||||
self.path.display(),
|
||||
err.error
|
||||
);
|
||||
} else {
|
||||
return Err(err).with_context(|| {
|
||||
format!(
|
||||
"Failed to rename temporary cache file to {}",
|
||||
self.path.display()
|
||||
)
|
||||
})?;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -176,6 +176,7 @@ pub(crate) fn format(
|
|||
duration
|
||||
);
|
||||
|
||||
// Store the caches.
|
||||
caches.persist()?;
|
||||
|
||||
// Report on any errors.
|
||||
|
|
|
|||
Loading…
Reference in New Issue