Patch #1029061: Always extract member names from the tarinfo.
This commit is contained in:
parent
39a317890f
commit
f3c5611fef
|
@ -814,7 +814,6 @@ class TarFile(object):
|
||||||
# Init datastructures
|
# Init datastructures
|
||||||
self.closed = False
|
self.closed = False
|
||||||
self.members = [] # list of members as TarInfo objects
|
self.members = [] # list of members as TarInfo objects
|
||||||
self.membernames = [] # names of members
|
|
||||||
self._loaded = False # flag if all members have been read
|
self._loaded = False # flag if all members have been read
|
||||||
self.offset = 0L # current position in the archive file
|
self.offset = 0L # current position in the archive file
|
||||||
self.inodes = {} # dictionary caching the inodes of
|
self.inodes = {} # dictionary caching the inodes of
|
||||||
|
@ -1034,12 +1033,10 @@ class TarFile(object):
|
||||||
than once in the archive, its last occurence is assumed to be the
|
than once in the archive, its last occurence is assumed to be the
|
||||||
most up-to-date version.
|
most up-to-date version.
|
||||||
"""
|
"""
|
||||||
self._check()
|
tarinfo = self._getmember(name)
|
||||||
if name not in self.membernames and not self._loaded:
|
if tarinfo is None:
|
||||||
self._load()
|
|
||||||
if name not in self.membernames:
|
|
||||||
raise KeyError, "filename %r not found" % name
|
raise KeyError, "filename %r not found" % name
|
||||||
return self._getmember(name)
|
return tarinfo
|
||||||
|
|
||||||
def getmembers(self):
|
def getmembers(self):
|
||||||
"""Return the members of the archive as a list of TarInfo objects. The
|
"""Return the members of the archive as a list of TarInfo objects. The
|
||||||
|
@ -1055,10 +1052,7 @@ class TarFile(object):
|
||||||
"""Return the members of the archive as a list of their names. It has
|
"""Return the members of the archive as a list of their names. It has
|
||||||
the same order as the list returned by getmembers().
|
the same order as the list returned by getmembers().
|
||||||
"""
|
"""
|
||||||
self._check()
|
return [tarinfo.name for tarinfo in self.getmembers()]
|
||||||
if not self._loaded:
|
|
||||||
self._load()
|
|
||||||
return self.membernames
|
|
||||||
|
|
||||||
def gettarinfo(self, name=None, arcname=None, fileobj=None):
|
def gettarinfo(self, name=None, arcname=None, fileobj=None):
|
||||||
"""Create a TarInfo object for either the file `name' or the file
|
"""Create a TarInfo object for either the file `name' or the file
|
||||||
|
@ -1307,7 +1301,7 @@ class TarFile(object):
|
||||||
blocks += 1
|
blocks += 1
|
||||||
self.offset += blocks * BLOCKSIZE
|
self.offset += blocks * BLOCKSIZE
|
||||||
|
|
||||||
self._record_member(tarinfo)
|
self.members.append(tarinfo)
|
||||||
|
|
||||||
def extract(self, member, path=""):
|
def extract(self, member, path=""):
|
||||||
"""Extract a member from the archive to the current working directory,
|
"""Extract a member from the archive to the current working directory,
|
||||||
|
@ -1632,7 +1626,7 @@ class TarFile(object):
|
||||||
# some old tar programs don't know DIRTYPE
|
# some old tar programs don't know DIRTYPE
|
||||||
tarinfo.type = DIRTYPE
|
tarinfo.type = DIRTYPE
|
||||||
|
|
||||||
self._record_member(tarinfo)
|
self.members.append(tarinfo)
|
||||||
return tarinfo
|
return tarinfo
|
||||||
|
|
||||||
#--------------------------------------------------------------------------
|
#--------------------------------------------------------------------------
|
||||||
|
@ -1647,8 +1641,8 @@ class TarFile(object):
|
||||||
# if there is data to follow.
|
# if there is data to follow.
|
||||||
# 2. set self.offset to the position where the next member's header will
|
# 2. set self.offset to the position where the next member's header will
|
||||||
# begin.
|
# begin.
|
||||||
# 3. call self._record_member() if the tarinfo object is supposed to
|
# 3. append the tarinfo object to self.members, if it is supposed to appear
|
||||||
# appear as a member of the TarFile object.
|
# as a member of the TarFile object.
|
||||||
# 4. return tarinfo or another valid TarInfo object.
|
# 4. return tarinfo or another valid TarInfo object.
|
||||||
|
|
||||||
def proc_gnulong(self, tarinfo):
|
def proc_gnulong(self, tarinfo):
|
||||||
|
@ -1729,7 +1723,7 @@ class TarFile(object):
|
||||||
self.offset += self._block(tarinfo.size)
|
self.offset += self._block(tarinfo.size)
|
||||||
tarinfo.size = origsize
|
tarinfo.size = origsize
|
||||||
|
|
||||||
self._record_member(tarinfo)
|
self.members.append(tarinfo)
|
||||||
return tarinfo
|
return tarinfo
|
||||||
|
|
||||||
# The type mapping for the next() method. The keys are single character
|
# The type mapping for the next() method. The keys are single character
|
||||||
|
@ -1757,20 +1751,17 @@ class TarFile(object):
|
||||||
"""Find an archive member by name from bottom to top.
|
"""Find an archive member by name from bottom to top.
|
||||||
If tarinfo is given, it is used as the starting point.
|
If tarinfo is given, it is used as the starting point.
|
||||||
"""
|
"""
|
||||||
|
# Ensure that all members have been loaded.
|
||||||
|
members = self.getmembers()
|
||||||
|
|
||||||
if tarinfo is None:
|
if tarinfo is None:
|
||||||
end = len(self.members)
|
end = len(members)
|
||||||
else:
|
else:
|
||||||
end = self.members.index(tarinfo)
|
end = members.index(tarinfo)
|
||||||
|
|
||||||
for i in xrange(end - 1, -1, -1):
|
for i in xrange(end - 1, -1, -1):
|
||||||
if name == self.membernames[i]:
|
if name == members[i].name:
|
||||||
return self.members[i]
|
return 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):
|
def _load(self):
|
||||||
"""Read through the entire archive file and look for readable
|
"""Read through the entire archive file and look for readable
|
||||||
|
|
|
@ -22,6 +22,9 @@ Extension modules
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- The (undocumented) tarfile.Tarfile.membernames has been removed;
|
||||||
|
applications should use the getmember function.
|
||||||
|
|
||||||
- httplib now offers symbolic constants for the HTTP status codes.
|
- httplib now offers symbolic constants for the HTTP status codes.
|
||||||
|
|
||||||
- SF bug #1028306: Trying to compare a ``datetime.date`` to a
|
- SF bug #1028306: Trying to compare a ``datetime.date`` to a
|
||||||
|
|
Loading…
Reference in New Issue