def get_tarinfo(self): """Generate a tarfile.TarInfo object based on self Doesn't set size based on stat, because we may want to replace data wiht other stream. Size should be set separately by calling function. """ ti = tarfile.TarInfo() if self.index: ti.name = "/".join(self.index) else: ti.name = "." if self.isdir(): ti.name += "/" # tar dir naming convention ti.size = 0 if self.type: # Lots of this is specific to tarfile.py, hope it doesn't # change much... if self.isreg(): ti.type = tarfile.REGTYPE ti.size = self.stat.st_size elif self.isdir(): ti.type = tarfile.DIRTYPE elif self.isfifo(): ti.type = tarfile.FIFOTYPE elif self.issym(): ti.type = tarfile.SYMTYPE ti.linkname = self.symtext elif self.isdev(): if self.type == "chr": ti.type = tarfile.CHRTYPE else: ti.type = tarfile.BLKTYPE ti.devmajor, ti.devminor = self.devnums else: raise PathException("Unrecognized type " + str(self.type)) ti.mode = self.mode ti.uid, ti.gid = self.stat.st_uid, self.stat.st_gid if self.stat.st_mtime < 0: log.Warn( _("Warning: %s has negative mtime, treating as 0.") % (util.ufn(self.get_relative_path()))) ti.mtime = 0 else: ti.mtime = int(self.stat.st_mtime) try: ti.uname = cached_ops.getpwuid(ti.uid)[0] except KeyError: ti.uname = '' try: ti.gname = cached_ops.getgrgid(ti.gid)[0] except KeyError: ti.gname = '' if ti.type in (tarfile.CHRTYPE, tarfile.BLKTYPE): if hasattr(os, "major") and hasattr(os, "minor"): ti.devmajor, ti.devminor = self.devnums else: # Currently we depend on an uninitiliazed tarinfo file to # already have appropriate headers. Still, might as well # make sure mode and size set. ti.mode, ti.size = 0, 0 return ti
def get_tarinfo(self): """Generate a tarfile.TarInfo object based on self Doesn't set size based on stat, because we may want to replace data wiht other stream. Size should be set separately by calling function. """ ti = tarfile.TarInfo() if self.index: ti.name = "/".join(self.index) else: ti.name = "." if self.isdir(): ti.name += "/" # tar dir naming convention ti.size = 0 if self.type: # Lots of this is specific to tarfile.py, hope it doesn't # change much... if self.isreg(): ti.type = tarfile.REGTYPE ti.size = self.stat.st_size elif self.isdir(): ti.type = tarfile.DIRTYPE elif self.isfifo(): ti.type = tarfile.FIFOTYPE elif self.issym(): ti.type = tarfile.SYMTYPE ti.linkname = self.symtext elif self.isdev(): if self.type == "chr": ti.type = tarfile.CHRTYPE else: ti.type = tarfile.BLKTYPE ti.devmajor, ti.devminor = self.devnums else: raise PathException("Unrecognized type " + str(self.type)) ti.mode = self.mode ti.uid, ti.gid = self.stat.st_uid, self.stat.st_gid if self.stat.st_mtime < 0: log.Warn(_("Warning: %s has negative mtime, treating as 0.") % (util.ufn(self.get_relative_path()))) ti.mtime = 0 else: ti.mtime = int(self.stat.st_mtime) try: ti.uname = cached_ops.getpwuid(ti.uid)[0] except KeyError: ti.uname = '' try: ti.gname = cached_ops.getgrgid(ti.gid)[0] except KeyError: ti.gname = '' if ti.type in (tarfile.CHRTYPE, tarfile.BLKTYPE): if hasattr(os, "major") and hasattr(os, "minor"): ti.devmajor, ti.devminor = self.devnums else: # Currently we depend on an uninitiliazed tarinfo file to # already have appropriate headers. Still, might as well # make sure mode and size set. ti.mode, ti.size = 0, 0 return ti