classification
Title: tarfile module does not correctly choose compression algorithms
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.5, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: berker.peksag, python-dev, serhiy.storchaka, wdv4758h
Priority: normal Keywords: patch

Created on 2015-02-09 13:03 by wdv4758h, last changed 2015-02-10 06:49 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
fix_compressions_dict.patch wdv4758h, 2015-02-09 13:03 fix compressions dict in tarfile module review
add_tarfile_cli_filetype_test.patch wdv4758h, 2015-02-09 17:41 tests for tarfile CLI review
add_tarfile_cli_filetype_test_refactor.patch wdv4758h, 2015-02-10 05:50 fix compressions dict in tarfile module (refactored) review
Repositories containing patches
https://bitbucket.org/wdv4758h/cpython/commits/92ac903167a52106435b32e89c1f2a119cb56686
https://bitbucket.org/wdv4758h/cpython/commits/ae6e80a4aadda9a139f568bda3bd4fba086dcc8b
https://bitbucket.org/wdv4758h/cpython/commits/0ef46feae8df5e67916f275521315f492ee344b7
Messages (11)
msg235604 - (view) Author: Chiu-Hsiang Hsu (wdv4758h) * Date: 2015-02-09 13:03
The command "python -m tarfile -c test.tar.bz2 test/" should create a file that is compressed by bzip2,
but actually the detection of compression algorithm that should be used is broken (for gz, xz, bz2).

fix it by prepending a dot to the keys of the dictionary
msg235606 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-02-09 13:13
Thank you for your patch. Could you provide tests?
msg235608 - (view) Author: Chiu-Hsiang Hsu (wdv4758h) * Date: 2015-02-09 13:28
yes

just wanna know is there a standard way to get file type by libmagic ?
msg235609 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-02-09 14:06
No need to use libmagic. tarfile.TarFile.gzopen() should fail if the file is not gzipped tar file. There CLI tests in Lib/test/test_tarfile.py. New test should create tar file with file name that ends with the '.gz' extension and check that it can be open and read with gzopen().
msg235611 - (view) Author: Chiu-Hsiang Hsu (wdv4758h) * Date: 2015-02-09 14:13
Oh, I can use it.
thx
msg235623 - (view) Author: Chiu-Hsiang Hsu (wdv4758h) * Date: 2015-02-09 17:41
Here is the tests.
msg235626 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-02-09 18:34
In general LGTM, but I have added few nitpicks on Rietveld.
msg235668 - (view) Author: Chiu-Hsiang Hsu (wdv4758h) * Date: 2015-02-10 05:50
Attached factored patch for tests.

It looks much better. :)
msg235669 - (view) Author: Chiu-Hsiang Hsu (wdv4758h) * Date: 2015-02-10 05:52
s/factored/refactored/
msg235671 - (view) Author: Roundup Robot (python-dev) Date: 2015-02-10 06:48
New changeset 2a06379f6562 by Serhiy Storchaka in branch '3.4':
Issue #23421: Fixed compression in tarfile CLI.  Patch by wdv4758h.
https://hg.python.org/cpython/rev/2a06379f6562

New changeset 5b70eb1cfad0 by Serhiy Storchaka in branch 'default':
Issue #23421: Fixed compression in tarfile CLI.  Patch by wdv4758h.
https://hg.python.org/cpython/rev/5b70eb1cfad0
msg235672 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-02-10 06:49
Thank you for your contribution.
History
Date User Action Args
2015-02-10 06:49:38serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg235672

stage: test needed -> resolved
2015-02-10 06:48:14python-devsetnosy: + python-dev
messages: + msg235671
2015-02-10 05:52:10wdv4758hsetmessages: + msg235669
2015-02-10 05:50:34wdv4758hsetfiles: + add_tarfile_cli_filetype_test_refactor.patch
hgrepos: + hgrepo299
messages: + msg235668
2015-02-09 18:34:49serhiy.storchakasetassignee: serhiy.storchaka
2015-02-09 18:34:36serhiy.storchakasetmessages: + msg235626
2015-02-09 17:41:38wdv4758hsetfiles: + add_tarfile_cli_filetype_test.patch
hgrepos: + hgrepo298
messages: + msg235623
2015-02-09 14:13:18wdv4758hsetmessages: + msg235611
2015-02-09 14:06:06serhiy.storchakasetmessages: + msg235609
2015-02-09 13:30:47wdv4758hsetversions: + Python 3.4
2015-02-09 13:28:34wdv4758hsetmessages: + msg235608
versions: - Python 3.4
2015-02-09 13:13:14serhiy.storchakasetversions: + Python 3.4
nosy: + berker.peksag, serhiy.storchaka

messages: + msg235606

stage: test needed
2015-02-09 13:03:37wdv4758hcreate