Skip to content

Commit 68657e2

Browse files
[3.12] gh-109980: Fix test_tarfile_vs_tar on macOS (GH-112905) (#112927)
gh-109980: Fix test_tarfile_vs_tar on macOS (GH-112905) On recentish macOS versions the system tar command includes system metadata (ACLs, extended attributes and resource forks) in the tar archive, which shutil.make_archive will not do. This can cause spurious test failures. (cherry picked from commit dd2ebdf) Co-authored-by: Ronald Oussoren <[email protected]>
1 parent c108080 commit 68657e2

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Lib/test/test_shutil.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,17 @@ def test_tarfile_vs_tar(self):
16151615
# now create another tarball using `tar`
16161616
tarball2 = os.path.join(root_dir, 'archive2.tar')
16171617
tar_cmd = ['tar', '-cf', 'archive2.tar', base_dir]
1618+
if sys.platform == 'darwin':
1619+
# macOS tar can include extended attributes,
1620+
# ACLs and other mac specific metadata into the
1621+
# archive (an recentish version of the OS).
1622+
#
1623+
# This feature can be disabled with the
1624+
# '--no-mac-metadata' option on macOS 11 or
1625+
# later.
1626+
import platform
1627+
if int(platform.mac_ver()[0].split('.')[0]) >= 11:
1628+
tar_cmd.insert(1, '--no-mac-metadata')
16181629
subprocess.check_call(tar_cmd, cwd=root_dir,
16191630
stdout=subprocess.DEVNULL)
16201631

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``test_tarfile_vs_tar`` in ``test_shutil`` for macOS, where system tar
2+
can include more information in the archive than :mod:`shutil.make_archive`.

0 commit comments

Comments
 (0)