Skip to content

Commit 2463a85

Browse files
committed
extract _transform_destination_path()
1 parent d95991d commit 2463a85

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Lib/tarfile.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,16 +2516,18 @@ def extractfile(self, member):
25162516
# blkdev, etc.), return None instead of a file object.
25172517
return None
25182518

2519+
def _transform_destination_path(self, targetpath):
2520+
# Build the destination pathname, replacing
2521+
# forward slashes to platform specific separators.
2522+
targetpath = targetpath.rstrip("/")
2523+
return targetpath.replace("/", os.sep)
2524+
25192525
def _extract_member(self, tarinfo, targetpath, set_attrs=True,
25202526
numeric_owner=False):
25212527
"""Extract the TarInfo object tarinfo to a physical
25222528
file called targetpath.
25232529
"""
2524-
# Fetch the TarInfo object for the given name
2525-
# and build the destination pathname, replacing
2526-
# forward slashes to platform specific separators.
2527-
targetpath = targetpath.rstrip("/")
2528-
targetpath = targetpath.replace("/", os.sep)
2530+
targetpath = self._transform_destination_path(targetpath)
25292531

25302532
# Create all upper directories.
25312533
upperdirs = os.path.dirname(targetpath)

0 commit comments

Comments
 (0)