Skip to content

Commit dd2ebdf

Browse files
gh-109980: Fix test_tarfile_vs_tar on macOS (#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.
1 parent 5bf7580 commit dd2ebdf

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Lib/test/test_shutil.py

+11
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,17 @@ def test_tarfile_vs_tar(self):
16701670
# now create another tarball using `tar`
16711671
tarball2 = os.path.join(root_dir, 'archive2.tar')
16721672
tar_cmd = ['tar', '-cf', 'archive2.tar', base_dir]
1673+
if sys.platform == 'darwin':
1674+
# macOS tar can include extended attributes,
1675+
# ACLs and other mac specific metadata into the
1676+
# archive (an recentish version of the OS).
1677+
#
1678+
# This feature can be disabled with the
1679+
# '--no-mac-metadata' option on macOS 11 or
1680+
# later.
1681+
import platform
1682+
if int(platform.mac_ver()[0].split('.')[0]) >= 11:
1683+
tar_cmd.insert(1, '--no-mac-metadata')
16731684
subprocess.check_call(tar_cmd, cwd=root_dir,
16741685
stdout=subprocess.DEVNULL)
16751686

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)