Changeset 1255 in products


Ignore:
Timestamp:
Aug 20, 2009 12:24:45 PM (15 years ago)
Author:
koval
Message:

added patch for tarfile module

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.transmogrifier/trunk/quintagroup/transmogrifier/patches.py

    r373 r1255  
    7979from Products.GenericSetup.context import TarballImportContext 
    8080TarballImportContext.listDirectory = listDirectory 
     81 
     82# patch for this bug in tarfile module - http://bugs.python.org/issue1719898 
     83from tarfile import TarInfo, nts, GNUTYPE_SPARSE, normpath, DIRTYPE 
     84def frombuf(cls, buf): 
     85    """Construct a TarInfo object from a 512 byte string buffer. 
     86    """ 
     87    tarinfo = cls() 
     88    tarinfo.name   = nts(buf[0:100]) 
     89    tarinfo.mode   = int(buf[100:108], 8) 
     90    tarinfo.uid    = int(buf[108:116],8) 
     91    tarinfo.gid    = int(buf[116:124],8) 
     92 
     93    # There are two possible codings for the size field we 
     94    # have to discriminate, see comment in tobuf() below. 
     95    if buf[124] != chr(0200): 
     96        tarinfo.size = long(buf[124:136], 8) 
     97    else: 
     98        tarinfo.size = 0L 
     99        for i in range(11): 
     100            tarinfo.size <<= 8 
     101            tarinfo.size += ord(buf[125 + i]) 
     102 
     103    tarinfo.mtime  = long(buf[136:148], 8) 
     104    tarinfo.chksum = int(buf[148:156], 8) 
     105    tarinfo.type   = buf[156:157] 
     106    tarinfo.linkname = nts(buf[157:257]) 
     107    tarinfo.uname  = nts(buf[265:297]) 
     108    tarinfo.gname  = nts(buf[297:329]) 
     109    try: 
     110        tarinfo.devmajor = int(buf[329:337], 8) 
     111        tarinfo.devminor = int(buf[337:345], 8) 
     112    except ValueError: 
     113        tarinfo.devmajor = tarinfo.devmajor = 0 
     114    tarinfo.prefix = buf[345:500] 
     115 
     116    # The prefix field is used for filenames > 100 in 
     117    # the POSIX standard. 
     118    # name = prefix + '/' + name 
     119    if tarinfo.type != GNUTYPE_SPARSE: 
     120        tarinfo.name = normpath(os.path.join(nts(tarinfo.prefix), tarinfo.name)) 
     121 
     122    # Some old tar programs represent a directory as a regular 
     123    # file with a trailing slash. 
     124    if tarinfo.isreg() and tarinfo.name.endswith("/"): 
     125        tarinfo.type = DIRTYPE 
     126 
     127    # Directory names should have a '/' at the end. 
     128    if tarinfo.isdir(): 
     129        tarinfo.name += "/" 
     130    return tarinfo 
     131 
     132frombuf = classmethod(frombuf) 
     133TarInfo.frombuf = frombuf 
Note: See TracChangeset for help on using the changeset viewer.