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

Use tarfile instead of GNU tar #27

Closed
dagss opened this issue Jan 11, 2013 · 2 comments
Closed

Use tarfile instead of GNU tar #27

dagss opened this issue Jan 11, 2013 · 2 comments

Comments

@dagss
Copy link
Member

dagss commented Jan 11, 2013

Currently GNU tar with the --strip-components option is needed, it would be better to use the builtin tarfile module.

There's prior art in "distlib" (in util.py) for supporting extraction of different extraction schemes:

https://bitbucket.org/vinay.sajip/distlib/src/393ccd9db71b2c77ed3973fc33bd5d28b090174b/distlib/util.py?at=default

Note that we support a "strip=1" feature so that one does not need to go "cd zlib-1.2.3" after extraction. To support this, the code would likely look something like this (this seems to be OK looking briefly at Python/Lib/tarfile.py):

def remove_prefix(tarinfo):
    tarinfo.path = pjoin(os.path.split(tarinfo.path)[strip:]) # but raise error if there are fewer components

tar = tarfile.open("sample.tar.gz")
tar.extractall(members=(remove_prefix(tarinfo) for tarinfo in tar))
tar.close()

Note: in test_source_cache.py, make_mock_archive/make_temporary_tarball should be modified to put items into a sub-directory to test the strip feature.

@dagss
Copy link
Member Author

dagss commented Jan 22, 2013

Also: GitSourceCache uses tar to extract output from "git archive", so instead one must read stdout and feed it to tarfile.

@certik
Copy link
Member

certik commented Feb 20, 2013

This is not very high priority, as tar works well for now.

@dagss dagss closed this as completed in 91709d1 Apr 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants