Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

untar_file: remove common leading directory before unpacking #12799

Merged
merged 4 commits into from
Jul 2, 2024

Conversation

encukou
Copy link
Contributor

@encukou encukou commented Jun 26, 2024

Fixes: #12781

This should fix the issue with unpacking hardlinks in tarballs.

Copy link
Member

@pfmoore pfmoore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, is it possible to create a functional test that fails the same way as the reported issue(s), so we can directly confirm that the fix works?

@encukou
Copy link
Contributor Author

encukou commented Jun 26, 2024

It should be possible, but I'm a bit lost in the codebase. What's a best way to add a functional test that builds a sdist and checks that it installs?

In this case, test sdist contain hardlinks and symlinks. Not all OSes allow those on disk, but they should handle a tarball that contains them, so it might need to be built with tarfile rather than something like setuptools.

@pfmoore
Copy link
Member

pfmoore commented Jun 26, 2024

I think you can add a pre-built tarfile to tests/data/packages and reference that via one of our test fixtures (data). Something like

def test_something(script: PipTestEnvironment, data: TestData):
    result = script.pip("install", "--no-index", "--find-links", data.find_links, "my_funky_sdist")

Or yes, you could do it manually by building a sdist in a temporary directory using the tarfile module. It's a bit more obvious what's going on if you do that, but it's more work.

@encukou
Copy link
Contributor Author

encukou commented Jun 26, 2024

I'll set up a Windows machine tomorrow to debug this.

@pfmoore
Copy link
Member

pfmoore commented Jun 26, 2024

They look unrelated to this change, I've just hit "rerun" in case they are intermittent failures.

@encukou
Copy link
Contributor Author

encukou commented Jun 27, 2024

Turns out it's because tarfile doesn't rewrite symlink targets on Windows.
sdists with symlinks that point to another directory are not (and AFAICS never were) unpacked correctly on Windows with symlinks enabled (i.e. in Developer Mode).

This became a bug in CPython after Windows started supporting symlinks. Fixing it there is not a high priority for me. Using os.path.sep in pip tests should be forward-compatible with a future fix.

@pfmoore
Copy link
Member

pfmoore commented Jun 28, 2024

Looks like there's still a CI failure to fix, and the branch needs to be brought up to date with main.

@encukou encukou force-pushed the gh-12781-tar-hardlink branch 2 times, most recently from f303024 to 54ddf75 Compare June 28, 2024 16:13
@encukou encukou force-pushed the gh-12781-tar-hardlink branch from 54ddf75 to 4fd295e Compare July 2, 2024 12:18
@pradyunsg pradyunsg merged commit 7b9d90d into pypa:main Jul 2, 2024
28 checks passed
@encukou encukou deleted the gh-12781-tar-hardlink branch July 3, 2024 10:53
pradyunsg added a commit to pradyunsg/pip that referenced this pull request Jul 7, 2024
untar_file: remove common leading directory before unpacking
@pradyunsg pradyunsg mentioned this pull request Jul 7, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[24.1] pip install py_find_1st fails with 24.1, whereas 24.0 does not
3 participants