MCPcopy Index your code
hub / github.com/python/cpython / _extract_member

Method _extract_member

Lib/tarfile.py:2601–2650  ·  view source on GitHub ↗

Extract the filtered TarInfo object tarinfo to a physical file called targetpath. filter_function is only used when extracting a *different* member (e.g. as fallback to creating a symlink)

(self, tarinfo, targetpath, set_attrs=True,
                        numeric_owner=False, *, filter_function=None,
                        extraction_root=None)

Source from the content-addressed store, hash-verified

2599 return None
2600
2601 def _extract_member(self, tarinfo, targetpath, set_attrs=True,
2602 numeric_owner=False, *, filter_function=None,
2603 extraction_root=None):
2604 """Extract the filtered TarInfo object tarinfo to a physical
2605 file called targetpath.
2606
2607 filter_function is only used when extracting a *different*
2608 member (e.g. as fallback to creating a symlink)
2609 """
2610 # Fetch the TarInfo object for the given name
2611 # and build the destination pathname, replacing
2612 # forward slashes to platform specific separators.
2613 targetpath = targetpath.rstrip("/")
2614 targetpath = targetpath.replace("/", os.sep)
2615
2616 # Create all upper directories.
2617 upperdirs = os.path.dirname(targetpath)
2618 if upperdirs and not os.path.exists(upperdirs):
2619 # Create directories that are not part of the archive with
2620 # default permissions.
2621 os.makedirs(upperdirs, exist_ok=True)
2622
2623 if tarinfo.islnk() or tarinfo.issym():
2624 self._dbg(1, "%s -> %s" % (tarinfo.name, tarinfo.linkname))
2625 else:
2626 self._dbg(1, tarinfo.name)
2627
2628 if tarinfo.isreg():
2629 self.makefile(tarinfo, targetpath)
2630 elif tarinfo.isdir():
2631 self.makedir(tarinfo, targetpath)
2632 elif tarinfo.isfifo():
2633 self.makefifo(tarinfo, targetpath)
2634 elif tarinfo.ischr() or tarinfo.isblk():
2635 self.makedev(tarinfo, targetpath)
2636 elif tarinfo.islnk() or tarinfo.issym():
2637 self.makelink_with_filter(
2638 tarinfo, targetpath,
2639 filter_function=filter_function,
2640 extraction_root=extraction_root)
2641 elif tarinfo.type not in SUPPORTED_TYPES:
2642 self.makeunknown(tarinfo, targetpath)
2643 else:
2644 self.makefile(tarinfo, targetpath)
2645
2646 if set_attrs:
2647 self.chown(tarinfo, targetpath, numeric_owner)
2648 if not tarinfo.issym():
2649 self.chmod(tarinfo, targetpath)
2650 self.utime(tarinfo, targetpath)
2651
2652 #--------------------------------------------------------------------------
2653 # Below are the different file methods. They are called via

Callers 2

_extract_oneMethod · 0.95
makelink_with_filterMethod · 0.95

Calls 15

_dbgMethod · 0.95
makefileMethod · 0.95
makedirMethod · 0.95
makefifoMethod · 0.95
makedevMethod · 0.95
makelink_with_filterMethod · 0.95
makeunknownMethod · 0.95
chownMethod · 0.95
chmodMethod · 0.95
utimeMethod · 0.95
islnkMethod · 0.80
issymMethod · 0.80

Tested by

no test coverage detected