Skip to content

Commit

Permalink
Avoid attempting rename in copy fallback path (#1546)
Browse files Browse the repository at this point in the history
## Summary

This _could_ fix #1454, but I'm
not sure. I was able to replicate by forcing a bunch of error states.
But, in short, if we fail to hardlink on the initial copy due to a file
existing, and then fail _again_, we fallback to copying. But if we copy,
then the tempfile doesn't exist, and so the `fs_err::rename(&tempfile,
&out_path)?;` will fail with "File not found".

This PR just ensures that the cases are explicitly mutually exclusive:
we only attempt to rename if the hardlink succeeded.
  • Loading branch information
charliermarsh authored Feb 16, 2024
1 parent 8050370 commit 4e0b6f8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions crates/install-wheel-rs/src/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,12 @@ fn hardlink_wheel_files(
// Removing and recreating would lead to race conditions.
let tempdir = tempdir_in(&site_packages)?;
let tempfile = tempdir.path().join(entry.file_name());
if fs::hard_link(path, &tempfile).is_err() {
if fs::hard_link(path, &tempfile).is_ok() {
fs_err::rename(&tempfile, &out_path)?;
} else {
fs::copy(path, &out_path)?;
attempt = Attempt::UseCopyFallback;
}
fs_err::rename(&tempfile, &out_path)?;
} else {
fs::copy(path, &out_path)?;
attempt = Attempt::UseCopyFallback;
Expand Down

0 comments on commit 4e0b6f8

Please sign in to comment.