Search code examples
pythonpermissionstarfile

Why does tarfile.extractall ignore errors by default?


Python's tarfile module ignores errors during extraction by default, unless errorlevel is set to either 1 or 2 (or debug to 1 if only error messages need to be printed).

Try doing a mkdir /tmp/foo && sudo chown root /tmp/foo && chmod a-w /tmp/foo and using tarfile to extract a .tar.gz file over /tmp/foo -- you will see that your Python code threw no exceptions at all. The files would not have been extracted over /tmp/foo which still is an empty directory.

Why this behavior? Who/what benefits from this default behavior? In other words, just who/what would want to ignore, say, permissions errors when decompressing a tarfile?


Solution

  • FWIW, this nasty behavior is will be changed in Python 2.7 and 3.2. http://svn.python.org/view?view=rev&revision=76780 Apparently the reason for ignoring the errors before was to be more like GNU tar, which ignores errors.