Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Make Windows tests ~27% faster by putting temp folder in dev drive #6680

Merged
merged 9 commits into from
Aug 27, 2024
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ jobs:
env:
CARGO_HOME: ${{ env.DEV_DRIVE }}/.cargo
RUSTUP_HOME: ${{ env.DEV_DRIVE }}/.rustup
UV_INTERNAL__TEST_DIR: ${{ env.DEV_DRIVE }}/tmp-uv
run: |
cargo nextest run --no-default-features --features python,pypi --workspace --status-level skip --failure-output immediate-final --no-fail-fast -j 20 --final-status-level slow

Expand Down
37 changes: 0 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ quote = { version = "1.0.36" }
rayon = { version = "1.8.0" }
reflink-copy = { version = "0.1.15" }
regex = { version = "1.10.2" }
reqwest = { version = "0.12.3", default-features = false, features = ["json", "gzip", "brotli", "stream", "rustls-tls", "rustls-tls-native-roots"] }
reqwest = { version = "0.12.3", default-features = false, features = ["json", "gzip", "stream", "rustls-tls", "rustls-tls-native-roots"] }
reqwest-middleware = { git = "https://github.com/astral-sh/reqwest-middleware", rev = "5e3eaf254b5bd481c75d2710eed055f95b756913" }
reqwest-retry = { git = "https://github.com/astral-sh/reqwest-middleware", rev = "5e3eaf254b5bd481c75d2710eed055f95b756913" }
rkyv = { version = "0.7.43", features = ["strict", "validation"] }
Expand Down
9 changes: 8 additions & 1 deletion crates/uv-cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,14 @@ impl Cache {

/// Create a temporary cache directory.
pub fn temp() -> Result<Self, io::Error> {
let temp_dir = tempfile::tempdir()?;
let temp_dir =
if let Ok(test_dir) = std::env::var("UV_INTERNAL__TEST_DIR").map(PathBuf::from) {
let uv_cache_dir = test_dir.join("uv-cache");
let _ = fs_err::create_dir_all(&uv_cache_dir);
tempfile::tempdir_in(uv_cache_dir)?
} else {
tempfile::tempdir()?
};
Ok(Self {
root: temp_dir.path().to_path_buf(),
refresh: Refresh::None(Timestamp::now()),
Expand Down
46 changes: 44 additions & 2 deletions crates/uv/src/commands/tool/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,59 @@ pub(crate) async fn uninstall(name: Option<PackageName>, printer: Printer) -> Re

// Clean up any empty directories.
if uv_fs::directories(installed_tools.root()).all(|path| uv_fs::is_temporary(&path)) {
fs_err::tokio::remove_dir_all(&installed_tools.root()).await?;
fs_err::tokio::remove_dir_all(&installed_tools.root())
.await
.ignore_currently_being_deleted()?;
if let Some(top_level) = installed_tools.root().parent() {
if uv_fs::directories(top_level).all(|path| uv_fs::is_temporary(&path)) {
fs_err::tokio::remove_dir_all(top_level).await?;
fs_err::tokio::remove_dir_all(top_level)
.await
.ignore_currently_being_deleted()?;
}
}
}

Ok(ExitStatus::Success)
}

trait IoErrorExt: std::error::Error + 'static {
#[inline]
fn is_in_process_of_being_deleted(&self) -> bool {
if cfg!(target_os = "windows") {
use std::error::Error;
let mut e: &dyn Error = &self;
loop {
if e.to_string().contains("The file cannot be opened because it is in the process of being deleted. (os error 303)") {
return true;
}
e = match e.source() {
Some(e) => e,
None => break,
}
}
}

false
}
}

impl IoErrorExt for std::io::Error {}

/// An extension trait to suppress "cannot open file because it's currently being deleted"
trait IgnoreCurrentlyBeingDeleted {
fn ignore_currently_being_deleted(self) -> Self;
}

impl IgnoreCurrentlyBeingDeleted for Result<(), std::io::Error> {
fn ignore_currently_being_deleted(self) -> Self {
match self {
Ok(()) => Ok(()),
Err(err) if err.is_in_process_of_being_deleted() => Ok(()),
Err(err) => Err(err),
}
}
}

/// Perform the uninstallation.
async fn do_uninstall(
installed_tools: &InstalledTools,
Expand Down
Loading