Make the backoff crate dependency Windows-only (#10002)

<!--
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

Since the `backoff` dependency is only *used* on Windows in practice,
this PR would ensure that it is only *compiled* on Windows, too. This is
helpful because it appears to be unmaintained upstream,
https://github.com/astral-sh/uv/issues/10001, and it would be nice to be
able to [drop it from
Fedora](https://bugzilla.redhat.com/show_bug.cgi?id=2329729).
<!-- What's the purpose of the change? What does it do, and why? -->

## Test Plan

<!-- How was it tested? -->
```
$ cargo run python install
$ cargo test
```
This commit is contained in:
Ben Beasley 2024-12-18 10:04:54 -05:00 committed by GitHub
parent 294da52610
commit 45b9aa8f41
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 7 deletions

View file

@ -17,7 +17,6 @@ workspace = true
[dependencies] [dependencies]
backoff = { workspace = true }
cachedir = { workspace = true } cachedir = { workspace = true }
dunce = { workspace = true } dunce = { workspace = true }
either = { workspace = true } either = { workspace = true }
@ -39,6 +38,7 @@ winsafe = { workspace = true }
rustix = { workspace = true } rustix = { workspace = true }
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
backoff = { workspace = true }
junction = { workspace = true } junction = { workspace = true }
[features] [features]

View file

@ -216,6 +216,7 @@ pub fn copy_atomic_sync(from: impl AsRef<Path>, to: impl AsRef<Path>) -> std::io
Ok(()) Ok(())
} }
#[cfg(windows)]
fn backoff_file_move() -> backoff::ExponentialBackoff { fn backoff_file_move() -> backoff::ExponentialBackoff {
backoff::ExponentialBackoffBuilder::default() backoff::ExponentialBackoffBuilder::default()
.with_initial_interval(std::time::Duration::from_millis(10)) .with_initial_interval(std::time::Duration::from_millis(10))
@ -229,7 +230,8 @@ pub async fn rename_with_retry(
from: impl AsRef<Path>, from: impl AsRef<Path>,
to: impl AsRef<Path>, to: impl AsRef<Path>,
) -> Result<(), std::io::Error> { ) -> Result<(), std::io::Error> {
if cfg!(windows) { #[cfg(windows)]
{
// On Windows, antivirus software can lock files temporarily, making them inaccessible. // On Windows, antivirus software can lock files temporarily, making them inaccessible.
// This is most common for DLLs, and the common suggestion is to retry the operation with // This is most common for DLLs, and the common suggestion is to retry the operation with
// some backoff. // some backoff.
@ -255,7 +257,9 @@ pub async fn rename_with_retry(
} }
}) })
.await .await
} else { }
#[cfg(not(windows))]
{
fs_err::tokio::rename(from, to).await fs_err::tokio::rename(from, to).await
} }
} }
@ -265,7 +269,8 @@ pub fn rename_with_retry_sync(
from: impl AsRef<Path>, from: impl AsRef<Path>,
to: impl AsRef<Path>, to: impl AsRef<Path>,
) -> Result<(), std::io::Error> { ) -> Result<(), std::io::Error> {
if cfg!(windows) { #[cfg(windows)]
{
// On Windows, antivirus software can lock files temporarily, making them inaccessible. // On Windows, antivirus software can lock files temporarily, making them inaccessible.
// This is most common for DLLs, and the common suggestion is to retry the operation with // This is most common for DLLs, and the common suggestion is to retry the operation with
// some backoff. // some backoff.
@ -299,7 +304,9 @@ pub fn rename_with_retry_sync(
), ),
) )
}) })
} else { }
#[cfg(not(windows))]
{
fs_err::rename(from, to) fs_err::rename(from, to)
} }
} }
@ -309,7 +316,8 @@ pub fn persist_with_retry_sync(
from: NamedTempFile, from: NamedTempFile,
to: impl AsRef<Path>, to: impl AsRef<Path>,
) -> Result<(), std::io::Error> { ) -> Result<(), std::io::Error> {
if cfg!(windows) { #[cfg(windows)]
{
// On Windows, antivirus software can lock files temporarily, making them inaccessible. // On Windows, antivirus software can lock files temporarily, making them inaccessible.
// This is most common for DLLs, and the common suggestion is to retry the operation with // This is most common for DLLs, and the common suggestion is to retry the operation with
// some backoff. // some backoff.
@ -364,7 +372,9 @@ pub fn persist_with_retry_sync(
format!("{err:?}"), format!("{err:?}"),
)), )),
} }
} else { }
#[cfg(not(windows))]
{
fs_err::rename(from, to) fs_err::rename(from, to)
} }
} }