Skip to content

Commit

Permalink
Fix hardlinks in tar unpacking
Browse files Browse the repository at this point in the history
In astral-sh/tokio-tar#2, we accidentally changed the `target_base` from the target base to the parent of the file. This would cause hardlink unpacking to fail.

Example: A hardlink at `hardlinked-0.1.0/pyproject.toml` pointing to `hardlinked-0.1.0/pyproject.toml.real` would try pointing to `hardlinked-0.1.0/hardlinked-0.1.0/pyproject.toml.real` instead and fail the unpacking.

The actual fix is krata-tokio-tar, on the uv side there are only tests.

Fixes #11213
  • Loading branch information
konstin committed Feb 4, 2025
1 parent 748582e commit 7a1fe0c
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ uv-workspace = { path = "crates/uv-workspace" }
anstream = { version = "0.6.15" }
anyhow = { version = "1.0.89" }
arcstr = { version = "1.2.0" }
astral-tokio-tar = { git = "https://github.com/astral-sh/tokio-tar", rev = "ba2b140f27d081c463335f0d68b5f8df8e6c845e" }
astral-tokio-tar = { git = "https://github.com/astral-sh/tokio-tar", rev = "efeaea927c7a40ee66121de2e1bebfd5d7a4a602" }
async-channel = { version = "2.3.1" }
async-compression = { version = "0.4.12", features = ["bzip2", "gzip", "xz", "zstd"] }
async-trait = { version = "0.1.82" }
Expand Down
77 changes: 77 additions & 0 deletions crates/uv/tests/it/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1746,3 +1746,80 @@ fn build_version_mismatch() -> Result<()> {
"###);
Ok(())
}

#[cfg(unix)] // Symlinks aren't universally available on windows.
#[test]
fn build_with_symlink() -> Result<()> {
let context = TestContext::new("3.12");
context
.temp_dir
.child("pyproject.toml.real")
.write_str(indoc! {r#"
[project]
name = "softlinked"
version = "0.1.0"
requires-python = ">=3.12"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
"#})?;
std::os::unix::fs::symlink(
context.temp_dir.child("pyproject.toml.real"),
context.temp_dir.child("pyproject.toml"),
)?;
context
.temp_dir
.child("src/softlinked/__init__.py")
.touch()?;
uv_snapshot!(context.filters(), context.build(), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Building source distribution...
Building wheel from source distribution...
Successfully built dist/softlinked-0.1.0.tar.gz
Successfully built dist/softlinked-0.1.0-py3-none-any.whl
"###);
Ok(())
}

#[test]
fn build_with_hardlink() -> Result<()> {
let context = TestContext::new("3.12");
context
.temp_dir
.child("pyproject.toml.real")
.write_str(indoc! {r#"
[project]
name = "hardlinked"
version = "0.1.0"
requires-python = ">=3.12"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
"#})?;
fs_err::hard_link(
context.temp_dir.child("pyproject.toml.real"),
context.temp_dir.child("pyproject.toml"),
)?;
context
.temp_dir
.child("src/hardlinked/__init__.py")
.touch()?;
uv_snapshot!(context.filters(), context.build(), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Building source distribution...
Building wheel from source distribution...
Successfully built dist/hardlinked-0.1.0.tar.gz
Successfully built dist/hardlinked-0.1.0-py3-none-any.whl
"###);
Ok(())
}

0 comments on commit 7a1fe0c

Please sign in to comment.