[Python-checkins] python/dist/src/Lib tarfile.py,1.10,1.11
akuchling at users.sourceforge.net
akuchling at users.sourceforge.net
Sun Jul 11 00:02:20 CEST 2004
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7570
Modified Files:
tarfile.py
Log Message:
[Patch 988444]
Read multiple special headers
- fixed/improved handling of extended/special headers
in read-mode (adding new extended headers should be
less painful now).
- improved nts() function.
- removed TarFile.chunks datastructure which is not
(and was never) needed.
- fixed TarInfo.tobuf(), fields could overflow with too
large values, values are now clipped.
Index: tarfile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/tarfile.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** tarfile.py 2 Jan 2004 15:44:29 -0000 1.10
--- tarfile.py 10 Jul 2004 22:02:11 -0000 1.11
***************
*** 136,140 ****
"""Convert a null-terminated string buffer to a python string.
"""
! return s.split(NUL, 1)[0]
def calc_chksum(buf):
--- 136,140 ----
"""Convert a null-terminated string buffer to a python string.
"""
! return s.rstrip(NUL)
def calc_chksum(buf):
***************
*** 714,718 ****
):
l = len(value)
! parts.append(value + (fieldsize - l) * NUL)
buf = "".join(parts)
--- 714,718 ----
):
l = len(value)
! parts.append(value[:fieldsize] + (fieldsize - l) * NUL)
buf = "".join(parts)
***************
*** 797,801 ****
self.members = [] # list of members as TarInfo objects
self.membernames = [] # names of members
- self.chunks = [0] # chunk cache
self._loaded = False # flag if all members have been read
self.offset = 0L # current position in the archive file
--- 797,800 ----
***************
*** 1282,1288 ****
self.offset += blocks * BLOCKSIZE
! self.members.append(tarinfo)
! self.membernames.append(tarinfo.name)
! self.chunks.append(self.offset)
def extract(self, member, path=""):
--- 1281,1285 ----
self.offset += blocks * BLOCKSIZE
! self._record_member(tarinfo)
def extract(self, member, path=""):
***************
*** 1552,1556 ****
# Read the next block.
! self.fileobj.seek(self.chunks[-1])
while True:
buf = self.fileobj.read(BLOCKSIZE)
--- 1549,1553 ----
# Read the next block.
! self.fileobj.seek(self.offset)
while True:
buf = self.fileobj.read(BLOCKSIZE)
***************
*** 1570,1574 ****
else:
# Block is empty or unreadable.
! if self.chunks[-1] == 0:
# If the first block is invalid. That does not
# look like a tar archive we can handle.
--- 1567,1571 ----
else:
# Block is empty or unreadable.
! if self.offset == 0:
# If the first block is invalid. That does not
# look like a tar archive we can handle.
***************
*** 1593,1602 ****
# method is registered in the TYPE_METH. If so, then call it.
if tarinfo.type in self.TYPE_METH:
! tarinfo = self.TYPE_METH[tarinfo.type](self, tarinfo)
! else:
! tarinfo.offset_data = self.offset
! if tarinfo.isreg() or tarinfo.type not in SUPPORTED_TYPES:
! # Skip the following data blocks.
! self.offset += self._block(tarinfo.size)
if tarinfo.isreg() and tarinfo.name[:-1] == "/":
--- 1590,1599 ----
# method is registered in the TYPE_METH. If so, then call it.
if tarinfo.type in self.TYPE_METH:
! return self.TYPE_METH[tarinfo.type](self, tarinfo)
!
! tarinfo.offset_data = self.offset
! if tarinfo.isreg() or tarinfo.type not in SUPPORTED_TYPES:
! # Skip the following data blocks.
! self.offset += self._block(tarinfo.size)
if tarinfo.isreg() and tarinfo.name[:-1] == "/":
***************
*** 1604,1610 ****
tarinfo.type = DIRTYPE
! self.members.append(tarinfo)
! self.membernames.append(tarinfo.name)
! self.chunks.append(self.offset)
return tarinfo
--- 1601,1605 ----
tarinfo.type = DIRTYPE
! self._record_member(tarinfo)
return tarinfo
***************
*** 1621,1625 ****
# 2. set self.offset to the position where the next member's header will
# begin.
! # 3. return a valid TarInfo object.
def proc_gnulong(self, tarinfo):
--- 1616,1622 ----
# 2. set self.offset to the position where the next member's header will
# begin.
! # 3. call self._record_member() if the tarinfo object is supposed to
! # appear as a member of the TarFile object.
! # 4. return tarinfo or another valid TarInfo object.
def proc_gnulong(self, tarinfo):
***************
*** 1637,1658 ****
count -= BLOCKSIZE
! if tarinfo.type == GNUTYPE_LONGNAME:
! name = nts(buf)
! if tarinfo.type == GNUTYPE_LONGLINK:
! linkname = nts(buf)
!
! buf = self.fileobj.read(BLOCKSIZE)
! tarinfo = TarInfo.frombuf(buf)
! tarinfo.offset = self.offset
! self.offset += BLOCKSIZE
! tarinfo.offset_data = self.offset
! tarinfo.name = name or tarinfo.name
! tarinfo.linkname = linkname or tarinfo.linkname
! if tarinfo.isreg() or tarinfo.type not in SUPPORTED_TYPES:
! # Skip the following data blocks.
! self.offset += self._block(tarinfo.size)
! return tarinfo
def proc_sparse(self, tarinfo):
--- 1634,1647 ----
count -= BLOCKSIZE
! # Fetch the next header
! next = self.next()
! next.offset = tarinfo.offset
! if tarinfo.type == GNUTYPE_LONGNAME:
! next.name = nts(buf)
! elif tarinfo.type == GNUTYPE_LONGLINK:
! next.linkname = nts(buf)
! return next
def proc_sparse(self, tarinfo):
***************
*** 1710,1713 ****
--- 1699,1704 ----
self.offset += self._block(tarinfo.size)
tarinfo.size = origsize
+
+ self._record_member(tarinfo)
return tarinfo
***************
*** 1746,1749 ****
--- 1737,1746 ----
return self.members[i]
+ def _record_member(self, tarinfo):
+ """Record a tarinfo object in the internal datastructures.
+ """
+ self.members.append(tarinfo)
+ self.membernames.append(tarinfo.name)
+
def _load(self):
"""Read through the entire archive file and look for readable
More information about the Python-checkins
mailing list