Lines Matching defs:tarinfo
710 def __init__(self, tarfile, tarinfo):
711 fileobj = _FileInFile(tarfile.fileobj, tarinfo.offset_data,
712 tarinfo.size, tarinfo.sparse)
725 def __init__(self, tarinfo):
726 self.tarinfo = tarinfo
727 super().__init__(f'member {tarinfo.name!r} has an absolute path')
730 def __init__(self, tarinfo, path):
731 self.tarinfo = tarinfo
733 super().__init__(f'{tarinfo.name!r} would be extracted to {path!r}, '
737 def __init__(self, tarinfo):
738 self.tarinfo = tarinfo
739 super().__init__(f'{tarinfo.name!r} is a special file')
742 def __init__(self, tarinfo):
743 self.tarinfo = tarinfo
744 super().__init__(f'{tarinfo.name!r} is a symlink to an absolute path')
747 def __init__(self, tarinfo, path):
748 self.tarinfo = tarinfo
750 super().__init__(f'{tarinfo.name!r} would link to {path!r}, '
1659 tarinfo = TarInfo # The default TarInfo class to use.
1666 tarinfo=None, dereference=None, ignore_zeros=None, encoding=None,
1703 if tarinfo is not None:
1704 self.tarinfo = tarinfo
1744 tarinfo = self.tarinfo.fromtarfile(self)
1745 self.members.append(tarinfo)
1756 buf = self.tarinfo.create_pax_global_header(self.pax_headers.copy())
2005 tarinfo = self._getmember(name.rstrip('/'))
2006 if tarinfo is None:
2008 return tarinfo
2024 return [tarinfo.name for tarinfo in self.getmembers()]
2053 tarinfo = self.tarinfo()
2054 tarinfo.tarfile = self # Not needed
2097 tarinfo.name = arcname
2098 tarinfo.mode = stmd
2099 tarinfo.uid = statres.st_uid
2100 tarinfo.gid = statres.st_gid
2102 tarinfo.size = statres.st_size
2104 tarinfo.size = 0
2105 tarinfo.mtime = statres.st_mtime
2106 tarinfo.type = type
2107 tarinfo.linkname = linkname
2110 tarinfo.uname = pwd.getpwuid(tarinfo.uid)[0]
2115 tarinfo.gname = grp.getgrgid(tarinfo.gid)[0]
2121 tarinfo.devmajor = os.major(statres.st_rdev)
2122 tarinfo.devminor = os.minor(statres.st_rdev)
2123 return tarinfo
2135 for tarinfo in members:
2137 if tarinfo.mode is None:
2140 _safe_print(stat.filemode(tarinfo.mode))
2141 _safe_print("%s/%s" % (tarinfo.uname or tarinfo.uid,
2142 tarinfo.gname or tarinfo.gid))
2143 if tarinfo.ischr() or tarinfo.isblk():
2145 ("%d,%d" % (tarinfo.devmajor, tarinfo.devminor)))
2147 _safe_print("%10d" % tarinfo.size)
2148 if tarinfo.mtime is None:
2152 % time.localtime(tarinfo.mtime)[:6])
2154 _safe_print(tarinfo.name + ("/" if tarinfo.isdir() else ""))
2157 if tarinfo.issym():
2158 _safe_print("-> " + tarinfo.linkname)
2159 if tarinfo.islnk():
2160 _safe_print("link to " + tarinfo.linkname)
2186 tarinfo = self.gettarinfo(name, arcname)
2188 if tarinfo is None:
2194 tarinfo = filter(tarinfo)
2195 if tarinfo is None:
2200 if tarinfo.isreg():
2202 self.addfile(tarinfo, f)
2204 elif tarinfo.isdir():
2205 self.addfile(tarinfo)
2212 self.addfile(tarinfo)
2214 def addfile(self, tarinfo, fileobj=None):
2215 """Add the TarInfo object `tarinfo' to the archive. If `fileobj' is
2216 given, it should be a binary file, and tarinfo.size bytes are read
2222 tarinfo = copy.copy(tarinfo)
2224 buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
2230 copyfileobj(fileobj, self.fileobj, tarinfo.size, bufsize=bufsize)
2231 blocks, remainder = divmod(tarinfo.size, BLOCKSIZE)
2237 self.members.append(tarinfo)
2278 tarinfo = self._get_extract_tarinfo(member, filter_function, path)
2279 if tarinfo is None:
2281 if tarinfo.isdir():
2285 directories.append(tarinfo)
2286 self._extract_one(tarinfo, path, set_attrs=not tarinfo.isdir(),
2293 for tarinfo in directories:
2294 dirpath = os.path.join(path, tarinfo.name)
2296 self.chown(tarinfo, dirpath, numeric_owner=numeric_owner)
2297 self.utime(tarinfo, dirpath)
2298 self.chmod(tarinfo, dirpath)
2317 tarinfo = self._get_extract_tarinfo(member, filter_function, path)
2318 if tarinfo is not None:
2319 self._extract_one(tarinfo, path, set_attrs, numeric_owner)
2324 tarinfo = self.getmember(member)
2326 tarinfo = member
2328 unfiltered = tarinfo
2330 tarinfo = filter_function(tarinfo, path)
2335 if tarinfo is None:
2339 if tarinfo.islnk():
2340 tarinfo = copy.copy(tarinfo)
2341 tarinfo._link_target = os.path.join(path, tarinfo.linkname)
2342 return tarinfo
2344 def _extract_one(self, tarinfo, path, set_attrs, numeric_owner):
2345 """Extract from filtered tarinfo to disk"""
2349 self._extract_member(tarinfo, os.path.join(path, tarinfo.name),
2386 tarinfo = self.getmember(member)
2388 tarinfo = member
2390 if tarinfo.isreg() or tarinfo.type not in SUPPORTED_TYPES:
2392 return self.fileobject(self, tarinfo)
2394 elif tarinfo.islnk() or tarinfo.issym():
2402 return self.extractfile(self._find_link_target(tarinfo))
2408 def _extract_member(self, tarinfo, targetpath, set_attrs=True,
2410 """Extract the TarInfo object tarinfo to a physical
2426 if tarinfo.islnk() or tarinfo.issym():
2427 self._dbg(1, "%s -> %s" % (tarinfo.name, tarinfo.linkname))
2429 self._dbg(1, tarinfo.name)
2431 if tarinfo.isreg():
2432 self.makefile(tarinfo, targetpath)
2433 elif tarinfo.isdir():
2434 self.makedir(tarinfo, targetpath)
2435 elif tarinfo.isfifo():
2436 self.makefifo(tarinfo, targetpath)
2437 elif tarinfo.ischr() or tarinfo.isblk():
2438 self.makedev(tarinfo, targetpath)
2439 elif tarinfo.islnk() or tarinfo.issym():
2440 self.makelink(tarinfo, targetpath)
2441 elif tarinfo.type not in SUPPORTED_TYPES:
2442 self.makeunknown(tarinfo, targetpath)
2444 self.makefile(tarinfo, targetpath)
2447 self.chown(tarinfo, targetpath, numeric_owner)
2448 if not tarinfo.issym():
2449 self.chmod(tarinfo, targetpath)
2450 self.utime(tarinfo, targetpath)
2457 def makedir(self, tarinfo, targetpath):
2461 if tarinfo.mode is None:
2471 def makefile(self, tarinfo, targetpath):
2475 source.seek(tarinfo.offset_data)
2478 if tarinfo.sparse is not None:
2479 for offset, size in tarinfo.sparse:
2482 target.seek(tarinfo.size)
2485 copyfileobj(source, target, tarinfo.size, ReadError, bufsize)
2487 def makeunknown(self, tarinfo, targetpath):
2491 self.makefile(tarinfo, targetpath)
2493 "extracted as regular file." % tarinfo.type)
2495 def makefifo(self, tarinfo, targetpath):
2503 def makedev(self, tarinfo, targetpath):
2509 mode = tarinfo.mode
2513 if tarinfo.isblk():
2519 os.makedev(tarinfo.devmajor, tarinfo.devminor))
2521 def makelink(self, tarinfo, targetpath):
2528 if tarinfo.issym():
2532 os.symlink(tarinfo.linkname, targetpath)
2534 if os.path.exists(tarinfo._link_target):
2535 os.link(tarinfo._link_target, targetpath)
2537 self._extract_member(self._find_link_target(tarinfo),
2541 self._extract_member(self._find_link_target(tarinfo),
2546 def chown(self, tarinfo, targetpath, numeric_owner):
2547 """Set owner of targetpath according to tarinfo. If numeric_owner
2554 g = tarinfo.gid
2555 u = tarinfo.uid
2558 if grp and tarinfo.gname:
2559 g = grp.getgrnam(tarinfo.gname)[2]
2563 if pwd and tarinfo.uname:
2564 u = pwd.getpwnam(tarinfo.uname)[2]
2572 if tarinfo.issym() and hasattr(os, "lchown"):
2579 def chmod(self, tarinfo, targetpath):
2580 """Set file permissions of targetpath according to tarinfo.
2582 if tarinfo.mode is None:
2585 os.chmod(targetpath, tarinfo.mode)
2589 def utime(self, tarinfo, targetpath):
2590 """Set modification time of targetpath according to tarinfo.
2592 mtime = tarinfo.mtime
2623 tarinfo = None
2626 tarinfo = self.tarinfo.fromtarfile(self)
2658 if tarinfo is not None:
2659 self.members.append(tarinfo)
2663 return tarinfo
2668 def _getmember(self, name, tarinfo=None, normalize=False):
2670 If tarinfo is given, it is used as the starting point.
2675 # Limit the member search list up to tarinfo.
2677 if tarinfo is not None:
2679 index = members.index(tarinfo)
2693 if tarinfo.offset == member.offset:
2706 raise ValueError(tarinfo)
2713 tarinfo = self.next()
2714 if tarinfo is None:
2727 def _find_link_target(self, tarinfo):
2731 if tarinfo.issym():
2733 linkname = "/".join(filter(None, (os.path.dirname(tarinfo.name), tarinfo.linkname)))
2738 linkname = tarinfo.linkname
2739 limit = tarinfo
2741 member = self._getmember(linkname, tarinfo=limit, normalize=True)
2760 tarinfo = self.next()
2762 yield tarinfo
2766 tarinfo = self.members[index]
2768 tarinfo = self.next()
2769 if not tarinfo:
2775 yield tarinfo