MCPcopy Index your code
hub / github.com/RustPython/RustPython / gettarinfo

Method gettarinfo

Lib/tarfile.py:2142–2246  ·  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

2140 return [tarinfo.name for tarinfo in self.getmembers()]
2141
2142 def gettarinfo(self, name=None, arcname=None, fileobj=None):
2143 """Create a TarInfo object from the result of os.stat or equivalent
2144 on an existing file. The file is either named by 'name', or
2145 specified as a file object 'fileobj' with a file descriptor. If
2146 given, 'arcname' specifies an alternative name for the file in the
2147 archive, otherwise, the name is taken from the 'name' attribute of
2148 'fileobj', or the 'name' argument. The name should be a text
2149 string.
2150 """
2151 self._check("awx")
2152
2153 # When fileobj is given, replace name by
2154 # fileobj's real name.
2155 if fileobj is not None:
2156 name = fileobj.name
2157
2158 # Building the name of the member in the archive.
2159 # Backward slashes are converted to forward slashes,
2160 # Absolute paths are turned to relative paths.
2161 if arcname is None:
2162 arcname = name
2163 drv, arcname = os.path.splitdrive(arcname)
2164 arcname = arcname.replace(os.sep, "/")
2165 arcname = arcname.lstrip("/")
2166
2167 # Now, fill the TarInfo object with
2168 # information specific for the file.
2169 tarinfo = self.tarinfo()
2170 tarinfo._tarfile = self # To be removed in 3.16.
2171
2172 # Use os.stat or os.lstat, depending on if symlinks shall be resolved.
2173 if fileobj is None:
2174 if not self.dereference:
2175 statres = os.lstat(name)
2176 else:
2177 statres = os.stat(name)
2178 else:
2179 statres = os.fstat(fileobj.fileno())
2180 linkname = ""
2181
2182 stmd = statres.st_mode
2183 if stat.S_ISREG(stmd):
2184 inode = (statres.st_ino, statres.st_dev)
2185 if not self.dereference and statres.st_nlink > 1 and \
2186 inode in self.inodes and arcname != self.inodes[inode]:
2187 # Is it a hardlink to an already
2188 # archived file?
2189 type = LNKTYPE
2190 linkname = self.inodes[inode]
2191 else:
2192 # The inode is added only if its valid.
2193 # For win32 it is always 0.
2194 type = REGTYPE
2195 if inode[0]:
2196 self.inodes[inode] = arcname
2197 elif stat.S_ISDIR(stmd):
2198 type = DIRTYPE
2199 elif stat.S_ISFIFO(stmd):

Callers 12

addMethod · 0.95
test_file_sizeMethod · 0.80
test_directory_sizeMethod · 0.80
test_link_sizeMethod · 0.80
test_symlink_sizeMethod · 0.80
test_missing_fileobjMethod · 0.80
test_add_twiceMethod · 0.80
test_add_hardlinkMethod · 0.80
test_addMethod · 0.80
setUpClassMethod · 0.80

Calls 10

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

Tested by 11

test_file_sizeMethod · 0.64
test_directory_sizeMethod · 0.64
test_link_sizeMethod · 0.64
test_symlink_sizeMethod · 0.64
test_missing_fileobjMethod · 0.64
test_add_twiceMethod · 0.64
test_add_hardlinkMethod · 0.64
test_addMethod · 0.64
setUpClassMethod · 0.64