From 59f4639863e6f47ded1400200d74406124a33ee2 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 6 Mar 2024 20:35:22 -0800 Subject: [PATCH] Close `RECORD` after reading entries during uninstall (#2259) ## Summary It turns out that by keeping the `RECORD` file open, older versions of Windows mark it for deletion, but don't allow it to be deleted until it's closed. As such, we end up leaving the `.dist-info` directory around, since it appears non-empty; but once the program terminates, we _do_ delete `RECORD`, leaving it empty. This then creates the impression that a package exists where it does not. Closes https://github.com/astral-sh/uv/issues/2074. --- crates/install-wheel-rs/src/uninstall.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/install-wheel-rs/src/uninstall.rs b/crates/install-wheel-rs/src/uninstall.rs index f1075cb31..de917c09e 100644 --- a/crates/install-wheel-rs/src/uninstall.rs +++ b/crates/install-wheel-rs/src/uninstall.rs @@ -16,15 +16,17 @@ pub fn uninstall_wheel(dist_info: &Path) -> Result { }; // Read the RECORD file. - let record_path = dist_info.join("RECORD"); - let mut record_file = match fs::File::open(&record_path) { - Ok(record_file) => record_file, - Err(err) if err.kind() == std::io::ErrorKind::NotFound => { - return Err(Error::MissingRecord(record_path)); - } - Err(err) => return Err(err.into()), + let record = { + let record_path = dist_info.join("RECORD"); + let mut record_file = match fs::File::open(&record_path) { + Ok(record_file) => record_file, + Err(err) if err.kind() == std::io::ErrorKind::NotFound => { + return Err(Error::MissingRecord(record_path)); + } + Err(err) => return Err(err.into()), + }; + read_record_file(&mut record_file)? }; - let record = read_record_file(&mut record_file)?; let mut file_count = 0usize; let mut dir_count = 0usize;