selftest broken under Python 2.5 because of tarfile API

Bug #123485 reported by Ian Clatworthy
2
Affects Status Importance Assigned to Milestone
Bazaar
Fix Released
High
Ian Clatworthy

Bug Description

selftest reports 15 errors and 1 failure and all of the problems are much the same. Here's a sample:

ERROR: test_repository_tarball (bzrlib.tests.test_smart.TestSmartServerRepositoryTarball)

vvvv[log from bzrlib.tests.test_smart.TestSmartServerRepositoryTarball.test_repository_tarball]
created control directory in file:///tmp/testbzr-F2dgbl.tmp/tmpo4Lu_H/work/
creating repository in file:///tmp/testbzr-F2dgbl.tmp/tmpo4Lu_H/work/.bzr/.
created control directory in file:///tmp/tmpbzrclonepBHxnO/
creating repository in file:///tmp/tmpbzrclonepBHxnO/.bzr/.
Using fetch logic to copy between KnitRepository('file:///tmp/testbzr-F2dgbl.tmp/tmpo4Lu_H/work/.bzr/')(<RepositoryFormatKnit1>) and KnitRepository('file:///tmp/tmpbzrclonepBHxnO/.bzr/')(<RepositoryFormatKnit1>)
fetch up to rev {None}

^^^^[log from bzrlib.tests.test_smart.TestSmartServerRepositoryTarball.test_repository_tarball]
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ian/bzr/bzr.dev/bzrlib/tests/test_smart.py", line 754, in test_repository_tarball
    response = request.execute(backing.local_abspath(''), 'bz2')
  File "/home/ian/bzr/bzr.dev/bzrlib/smart/request.py", line 65, in execute
    return self.do(*args)
  File "/home/ian/bzr/bzr.dev/bzrlib/smart/repository.py", line 48, in do
    return self.do_repository_request(repository, *args)
  File "/home/ian/bzr/bzr.dev/bzrlib/smart/repository.py", line 202, in do_repository_request
    return self._tarfile_response(controldir_name, compression)
  File "/home/ian/bzr/bzr.dev/bzrlib/smart/repository.py", line 216, in _tarfile_response
    self._tarball_of_dir(tmp_dirname, compression, temp.file)
  File "/home/ian/bzr/bzr.dev/bzrlib/smart/repository.py", line 226, in _tarball_of_dir
    tarball = tarfile.open(fileobj=ofile, mode='w|' + compression)
  File "tarfile.py", line 1168, in open
    _Stream(name, filemode, comptype, fileobj, bufsize))
  File "tarfile.py", line 1047, in __init__
    self.name = os.path.abspath(name)
  File "posixpath.py", line 402, in abspath
    if not isabs(path):
  File "posixpath.py", line 49, in isabs
    return s.startswith('/')
AttributeError: 'NoneType' object has no attribute 'startswith'

spiv did a quick investigation and confirmed that the problem is related to library API changes from Python 2.4 and Python 2.5.

Revision history for this message
Andrew Bennetts (spiv) wrote :

Specifically, it's a bug in Python 2.5.1. It works with 2.5.0, 2.4.x, and should work with 2.5.2 and 2.6 when they are released.

Martin suggests that passing the name we used to pass, in addition to fileobj, to the TarFile constructor will avoid the bug, and still give the behaviour we want (i.e. allow this to work on Windows). Looking at the various versions of tarfile.py, this does look like it will do what we want.

So:

    tarball = tarfile.open(fileobj=ofile, name=ofile.name, mode='w|' + compression)

Revision history for this message
Martin Pool (mbp) wrote : Re: [Bug 123485] Re: selftest broken under Python 2.5 because of tarfile API

On 7/2/07, Andrew Bennetts <email address hidden> wrote:
> Specifically, it's a bug in Python 2.5.1. It works with 2.5.0, 2.4.x,
> and should work with 2.5.2 and 2.6 when they are released.
>
> Martin suggests that passing the name we used to pass, in addition to
> fileobj, to the TarFile constructor will avoid the bug, and still give
> the behaviour we want (i.e. allow this to work on Windows). Looking at
> the various versions of tarfile.py, this does look like it will do what
> we want.
>
> So:
>
> tarball = tarfile.open(fileobj=ofile, name=ofile.name, mode='w|' +
> compression)

I think you should set it to the basename of the file, I think putting
in the full path causes some other problems.

--
Martin

Changed in bzr:
assignee: nobody → ian-clatworthy
importance: Undecided → High
status: New → Fix Committed
Revision history for this message
Alexander Belchenko (bialix) wrote :

fix merged as bzr.dev.revno.2574

Changed in bzr:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.