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.
This commit is contained in:
Charlie Marsh 2024-03-06 20:35:22 -08:00 committed by GitHub
parent b061db094d
commit 59f4639863
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;