mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-13 17:25:41 +00:00
Overwrite individual files when reflinking (#556)
Similar to #516, but for individual files. ## Test Plan Ran: ```sh cargo run -p puffin-cli -- pip-uninstall plaid-python mkdir -p /Users/crmarsh/workspace/puffin/.venv/lib/python3.10/site-packages/tests echo "x=1" > /Users/crmarsh/workspace/puffin/.venv/lib/python3.10/site-packages/tests/__init__.py cargo run -p puffin-cli -- pip-sync requirements.txt --no-cache --verbose ```
This commit is contained in:
parent
5fddcc362e
commit
af13c83177
1 changed files with 16 additions and 11 deletions
|
|
@ -256,7 +256,7 @@ fn clone_wheel_files(
|
||||||
// On macOS, directly can be recursively copied with a single `clonefile` call.
|
// On macOS, directly can be recursively copied with a single `clonefile` call.
|
||||||
// So we only need to iterate over the top-level of the directory, and copy each file or
|
// So we only need to iterate over the top-level of the directory, and copy each file or
|
||||||
// subdirectory unless the subdirectory exists already in which case we'll need to recursively
|
// subdirectory unless the subdirectory exists already in which case we'll need to recursively
|
||||||
// merge its contents with the existing direcotry.
|
// merge its contents with the existing directory.
|
||||||
for entry in fs::read_dir(wheel.as_ref())? {
|
for entry in fs::read_dir(wheel.as_ref())? {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
let from = entry.path();
|
let from = entry.path();
|
||||||
|
|
@ -276,18 +276,23 @@ fn clone_recursive(from: &Path, to: &Path) -> Result<(), Error> {
|
||||||
debug!("Cloning {} to {}", from.display(), to.display());
|
debug!("Cloning {} to {}", from.display(), to.display());
|
||||||
let reflink = reflink_copy::reflink(from, to);
|
let reflink = reflink_copy::reflink(from, to);
|
||||||
|
|
||||||
// If copying fails and the directory exists already, it must be merged recursively
|
if reflink
|
||||||
if from.is_dir()
|
|
||||||
&& reflink
|
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.is_err_and(|err| matches!(err.kind(), std::io::ErrorKind::AlreadyExists))
|
.is_err_and(|err| matches!(err.kind(), std::io::ErrorKind::AlreadyExists))
|
||||||
{
|
{
|
||||||
|
// If copying fails and the directory exists already, it must be merged recursively.
|
||||||
|
if from.is_dir() {
|
||||||
for entry in fs::read_dir(from)? {
|
for entry in fs::read_dir(from)? {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
let child_from = entry.path();
|
let child_from = entry.path();
|
||||||
let child_to = to.join(child_from.strip_prefix(from).unwrap());
|
let child_to = to.join(child_from.strip_prefix(from).unwrap());
|
||||||
clone_recursive(child_from.as_path(), child_to.as_path())?;
|
clone_recursive(child_from.as_path(), child_to.as_path())?;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// If file already exists, remove it and overwrite.
|
||||||
|
fs::remove_file(to)?;
|
||||||
|
reflink_copy::reflink(from, to)?;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Other errors should be tracked
|
// Other errors should be tracked
|
||||||
reflink.map_err(|err| Error::Reflink {
|
reflink.map_err(|err| Error::Reflink {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue