Skip to content

Commit

Permalink
Close RECORD after reading entries during uninstall (#2259)
Browse files Browse the repository at this point in the history
## 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 #2074.
  • Loading branch information
charliermarsh authored Mar 7, 2024
1 parent b061db0 commit 59f4639
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions crates/install-wheel-rs/src/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ pub fn uninstall_wheel(dist_info: &Path) -> Result<Uninstall, Error> {
};

// 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;
Expand Down

0 comments on commit 59f4639

Please sign in to comment.