mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 13:25:00 +00:00
Only fall back to copy when the first hard linking failed (#268)
Hard linking might not be supported but we (afaik) can't detect this ahead of time, so we'll try hard linking the first file, if this succeeds we'll know later hard linking errors are not due to lack of os/fs support, if it fails we'll switch to copying for the rest of the install. Follow up to https://github.com/astral-sh/puffin/pull/237#discussion_r1376705137
This commit is contained in:
parent
b0678aa6fc
commit
c6aa1cd7a3
1 changed files with 13 additions and 4 deletions
|
@ -361,7 +361,11 @@ fn hardlink_wheel_files(
|
|||
) -> Result<usize, Error> {
|
||||
let mut count = 0usize;
|
||||
|
||||
// Avoid causing the same error for every file
|
||||
// Hard linking might not be supported but we (afaik) can't detect this ahead of time, so we'll
|
||||
// try hard linking the first file, if this succeeds we'll know later hard linking errors are
|
||||
// not due to lack of os/fs support, if it fails we'll switch to copying for the rest of the
|
||||
// install
|
||||
let mut first_try_hard_linking = true;
|
||||
let mut use_copy_fallback = false;
|
||||
|
||||
// Walk over the directory.
|
||||
|
@ -383,10 +387,15 @@ fn hardlink_wheel_files(
|
|||
} else {
|
||||
let hard_link_result = fs::hard_link(entry.path(), &out_path);
|
||||
// Once https://github.com/rust-lang/rust/issues/86442 is stable, use that
|
||||
if hard_link_result.is_err() {
|
||||
fs::copy(entry.path(), &out_path)?;
|
||||
use_copy_fallback = true;
|
||||
if let Err(err) = hard_link_result {
|
||||
if first_try_hard_linking {
|
||||
fs::copy(entry.path(), &out_path)?;
|
||||
use_copy_fallback = true;
|
||||
} else {
|
||||
return Err(err.into());
|
||||
}
|
||||
}
|
||||
first_try_hard_linking = false;
|
||||
}
|
||||
|
||||
count += 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue