Fix sdist with long directories (#12764)

I removed the `set_cksum` as the value of it is replaced inside of
`append_data`.

## Summary

This should fix #12762 but I don't know how to test it.

---------

Co-authored-by: konstin <konstin@mailbox.org>
This commit is contained in:
leiserfg 2025-04-09 15:01:21 +02:00 committed by GitHub
parent 173d6f73d3
commit 980599f4fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 45 additions and 7 deletions

View file

@ -285,7 +285,6 @@ impl DirectoryWriter for TarGzWriter {
// Reasonable default to avoid 0o000 permissions, the user's umask will be applied on
// unpacking.
header.set_mode(0o644);
header.set_cksum();
self.tar
.append_data(&mut header, path, Cursor::new(bytes))
.map_err(|err| Error::TarWrite(self.path.clone(), err))?;
@ -307,7 +306,6 @@ impl DirectoryWriter for TarGzWriter {
header.set_mode(0o644);
}
header.set_size(metadata.len());
header.set_cksum();
let reader = BufReader::new(File::open(file)?);
self.tar
.append_data(&mut header, path, reader)
@ -320,13 +318,9 @@ impl DirectoryWriter for TarGzWriter {
// Directories are always executable, which means they can be listed.
header.set_mode(0o755);
header.set_entry_type(EntryType::Directory);
header
.set_path(directory)
.map_err(|err| Error::TarWrite(self.path.clone(), err))?;
header.set_size(0);
header.set_cksum();
self.tar
.append(&header, io::empty())
.append_data(&mut header, directory, io::empty())
.map_err(|err| Error::TarWrite(self.path.clone(), err))?;
Ok(())
}

View file

@ -547,3 +547,47 @@ fn build_module_name_normalization() -> Result<()> {
Ok(())
}
#[test]
fn build_sdist_with_long_path() -> Result<()> {
let context = TestContext::new("3.12");
let temp_dir = TempDir::new()?;
context
.temp_dir
.child("pyproject.toml")
.write_str(indoc! {r#"
[project]
name = "foo"
version = "1.0.0"
[build-system]
requires = ["uv_build>=0.6,<0.7"]
build-backend = "uv_build"
"#})?;
context
.temp_dir
.child("src/foo/__init__.py")
.write_str(r#"print("Hi from foo")"#)?;
let long_path = format!("src/foo/l{}ng/__init__.py", "o".repeat(100));
context
.temp_dir
.child(long_path)
.write_str(r#"print("Hi from foo")"#)?;
uv_snapshot!(context
.build_backend()
.arg("build-sdist")
.arg(temp_dir.path())
.env("UV_PREVIEW", "1"), @r###"
success: true
exit_code: 0
----- stdout -----
foo-1.0.0.tar.gz
----- stderr -----
"###);
Ok(())
}