MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / gettarinfo

Method gettarinfo

tools/python-3.11.9-amd64/Lib/tarfile.py:2005–2102  ·  view source on GitHub ↗

Create a TarInfo object from the result of os.stat or equivalent on an existing file. The file is either named by `name', or specified as a file object `fileobj' with a file descriptor. If given, `arcname' specifies an alternative name for the file in the

(self, name=None, arcname=None, fileobj=None)

Source from the content-addressed store, hash-verified

2003 return [tarinfo.name for tarinfo in self.getmembers()]
2004
2005 def gettarinfo(self, name=None, arcname=None, fileobj=None):
2006 """Create a TarInfo object from the result of os.stat or equivalent
2007 on an existing file. The file is either named by `name', or
2008 specified as a file object `fileobj' with a file descriptor. If
2009 given, `arcname' specifies an alternative name for the file in the
2010 archive, otherwise, the name is taken from the 'name' attribute of
2011 'fileobj', or the 'name' argument. The name should be a text
2012 string.
2013 """
2014 self._check("awx")
2015
2016 # When fileobj is given, replace name by
2017 # fileobj's real name.
2018 if fileobj is not None:
2019 name = fileobj.name
2020
2021 # Building the name of the member in the archive.
2022 # Backward slashes are converted to forward slashes,
2023 # Absolute paths are turned to relative paths.
2024 if arcname is None:
2025 arcname = name
2026 drv, arcname = os.path.splitdrive(arcname)
2027 arcname = arcname.replace(os.sep, "/")
2028 arcname = arcname.lstrip("/")
2029
2030 # Now, fill the TarInfo object with
2031 # information specific for the file.
2032 tarinfo = self.tarinfo()
2033 tarinfo.tarfile = self # Not needed
2034
2035 # Use os.stat or os.lstat, depending on if symlinks shall be resolved.
2036 if fileobj is None:
2037 if not self.dereference:
2038 statres = os.lstat(name)
2039 else:
2040 statres = os.stat(name)
2041 else:
2042 statres = os.fstat(fileobj.fileno())
2043 linkname = ""
2044
2045 stmd = statres.st_mode
2046 if stat.S_ISREG(stmd):
2047 inode = (statres.st_ino, statres.st_dev)
2048 if not self.dereference and statres.st_nlink > 1 and \
2049 inode in self.inodes and arcname != self.inodes[inode]:
2050 # Is it a hardlink to an already
2051 # archived file?
2052 type = LNKTYPE
2053 linkname = self.inodes[inode]
2054 else:
2055 # The inode is added only if its valid.
2056 # For win32 it is always 0.
2057 type = REGTYPE
2058 if inode[0]:
2059 self.inodes[inode] = arcname
2060 elif stat.S_ISDIR(stmd):
2061 type = DIRTYPE
2062 elif stat.S_ISFIFO(stmd):

Callers 1

addMethod · 0.95

Calls 9

_checkMethod · 0.95
lstripMethod · 0.80
lstatMethod · 0.80
readlinkMethod · 0.80
replaceMethod · 0.45
statMethod · 0.45
filenoMethod · 0.45
majorMethod · 0.45
minorMethod · 0.45

Tested by

no test coverage detected