I ran into a bug using the tarfile module with
compression from a directory that did not exist
anymore, and this exhibits a bug in the tarfile module.
I'm not completely sure how to fix it with certainty,
so instead of filing a quick patch, I submit a bug so
people familiar with the module can have a look first.
The problem is that when you open a tarfile with gz or
bz2 compression, the TarFile object is opened with a
filename that is not absolute, just local (basename is
called) but the actual file is using a file-like object.
Now, when you add a new entry, there is a check in the
TarFile.add method that checks if we're not adding the
archive itself into the tarfile, and this method calls
abspath. Calling abspath on the name that has been
basename'd is incorrect and a bug. It happens not to
fail nor cause any problems when called from an
existing directory (the test returns false), but it
does not do the job it is supposed to. When the CWD
has been deleted, calling abspath fails with an
OSError, which brings out the problem.
Some code to reproduce the bug is provided in an
attachment.
|