def init_from_tarinfo(self, tarinfo):
"""Set data from tarinfo object (part of tarfile module)"""
# Set the typepp
type = tarinfo.type
if type == tarfile.REGTYPE or type == tarfile.AREGTYPE:
self.type = "reg"
elif type == tarfile.LNKTYPE:
raise PathException("Hard links not supported yet")
elif type == tarfile.SYMTYPE:
self.type = "sym"
self.symtext = tarinfo.linkname
elif type == tarfile.CHRTYPE:
self.type = "chr"
self.devnums = (tarinfo.devmajor, tarinfo.devminor)
elif type == tarfile.BLKTYPE:
self.type = "blk"
self.devnums = (tarinfo.devmajor, tarinfo.devminor)
elif type == tarfile.DIRTYPE:
self.type = "dir"
elif type == tarfile.FIFOTYPE:
self.type = "fifo"
else:
raise PathException("Unknown tarinfo type %s" % (type,))
self.mode = tarinfo.mode
self.stat = StatResult()
""" Set user and group id
use numeric id if name lookup fails
OR
--numeric-owner is set
"""
try:
if globals.numeric_owner:
raise KeyError
self.stat.st_uid = cached_ops.getpwnam(tarinfo.uname)[2]
except KeyError:
self.stat.st_uid = tarinfo.uid
try:
if globals.numeric_owner:
raise KeyError
self.stat.st_gid = cached_ops.getgrnam(tarinfo.gname)[2]
except KeyError:
self.stat.st_gid = tarinfo.gid
self.stat.st_mtime = int(tarinfo.mtime)
if self.stat.st_mtime < 0:
log.Warn(_("Warning: %s has negative mtime, treating as 0.")
% (util.ufn(tarinfo.name)))
self.stat.st_mtime = 0
self.stat.st_size = tarinfo.size
评论列表
文章目录