Changeset 403


Ignore:
Timestamp:
24-06-09 17:17:49 (4 years ago)
Author:
thomas
Message:
  • moap/test/test_vcs_svn.py:
  • moap/vcs/vcs.py: Fix for Python 2.3 by avoiding extractall, and working around a hardlinking bug in tarfile in python 2.3
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r402 r403  
     12009-06-24  Thomas Vander Stichele  <thomas at apestaart dot org> 
     2 
     3        * moap/test/test_vcs_svn.py: 
     4        * moap/vcs/vcs.py: 
     5          Fix for Python 2.3 by avoiding extractall, and working around 
     6          a hardlinking bug in tarfile in python 2.3 
     7 
    182009-06-24  Thomas Vander Stichele  <thomas at apestaart dot org> 
    29 
  • trunk/moap/test/test_vcs_svn.py

    r366 r403  
    88import tempfile 
    99 
     10from moap.util import log 
    1011from moap.vcs import svn 
    1112 
     
    268269    def assertBackupRestore(self): 
    269270        # do a backup and restore and check 
    270         fd, archive = tempfile.mkstemp(suffix='tar.gz', prefix="moap.test.") 
     271        fd, archive = tempfile.mkstemp(suffix='.tar.gz', prefix="moap.test.") 
    271272        os.close(fd) 
    272273 
    273274        # backup does a test restore 
     275        log.debug('test', 'backing up archive %s', archive) 
    274276        self.vcs.backup(archive) 
    275277 
  • trunk/moap/vcs/vcs.py

    r366 r403  
    350350        """ 
    351351        mode = 'w:' 
     352        suffix = '.tar' 
    352353        if archive.endswith('.gz'): 
    353354            mode = 'w:gz' 
     355            suffix = '.tar.gz' 
    354356        if archive.endswith('.bz2'): 
    355357            mode = 'w:bw2' 
    356  
     358            suffix = '.tar.bz2' 
     359 
     360        # P2.4 
     361        # Pre-2.5, tarfile has a bug, creating hardlinks for temporary files 
     362        # if the temporary files get deleted right after adding. 
     363        # See http://mail.python.org/pipermail/python-bugs-list/2005-October/030793.html 
     364        # the workaround chosen is to keep the temporary files until after 
     365        # closing 
    357366        tar = tarfile.TarFile.open(name=archive, mode=mode) 
    358367 
    359368        # store the diff 
    360         (fd, path) = tempfile.mkstemp(prefix='moap.backup.diff.') 
     369        (fd, diffpath) = tempfile.mkstemp(prefix='moap.backup.diff.') 
    361370        diff = self.diff('') 
    362371        if diff: 
    363372            os.write(fd, diff + '\n') 
    364373        os.close(fd) 
    365         tar.add(path, arcname='diff') 
    366         os.unlink(path) 
     374        tar.add(diffpath, arcname='diff') 
    367375 
    368376        # store the checkout commands 
    369         (fd, path) = tempfile.mkstemp(prefix='moap.backup.checkout.') 
     377        (fd, checkoutpath) = tempfile.mkstemp(prefix='moap.backup.checkout.') 
    370378        os.write(fd, "#!/bin/sh\n" + self.getCheckoutCommands()) 
    371379        os.close(fd) 
    372         os.chmod(path, 0755) 
    373         tar.add(path, arcname='checkout.sh') 
    374         os.unlink(path) 
     380        os.chmod(checkoutpath, 0755) 
     381        tar.add(checkoutpath, arcname='checkout.sh') 
    375382 
    376383        # store the unignored files 
     
    384391            tar.add(abspath, 'unignored/' + rel) 
    385392        tar.close() 
     393        os.unlink(diffpath) 
     394        os.unlink(checkoutpath) 
    386395 
    387396        # now verify the backup 
    388         restoreDir = tempfile.mkdtemp(prefix="moap.test.") 
     397        restoreDir = tempfile.mkdtemp(prefix="moap.test.restore.") 
    389398        os.rmdir(restoreDir) 
    390399        self.restore(archive, restoreDir) 
     
    414423        oldPath = os.getcwd() 
    415424 
     425        # P2.3: tarfile.extractall only exists since 2.5 
    416426        tar = tarfile.TarFile.open(name=archive) 
    417         tar.extractall(path) 
     427        try: 
     428            tar.extractall(path) 
     429        except AttributeError: 
     430            # do it the shell way 
     431            self.debug('Restoring by using tar directly') 
     432            os.system('mkdir -p %s' % path) 
     433            if archive.endswith('.gz'): 
     434                os.system('cd %s; tar xzf %s' % (path, archive)) 
     435            elif archive.endswith('.bz2'): 
     436                os.system('cd %s; tar xjf %s' % (path, archive)) 
     437            else: 
     438                raise AssertionError("Don't know how to handle %s" % archive) 
    418439 
    419440        # start with the checkout 
Note: See TracChangeset for help on using the changeset viewer.