Skip to content

Commit 95f5c8c

Browse files
[3.11] gh-109980: Fix test_tarfile_vs_tar on macOS (GH-112905) (#112928)
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 4cc9e87 commit 95f5c8c

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
@@ -1446,6 +1446,17 @@ def test_tarfile_vs_tar(self):
14461446
# now create another tarball using `tar`
14471447
tarball2 = os.path.join(root_dir, 'archive2.tar')
14481448
tar_cmd = ['tar', '-cf', 'archive2.tar', base_dir]
1449+
if sys.platform == 'darwin':
1450+
# macOS tar can include extended attributes,
1451+
# ACLs and other mac specific metadata into the
1452+
# archive (an recentish version of the OS).
1453+
#
1454+
# This feature can be disabled with the
1455+
# '--no-mac-metadata' option on macOS 11 or
1456+
# later.
1457+
import platform
1458+
if int(platform.mac_ver()[0].split('.')[0]) >= 11:
1459+
tar_cmd.insert(1, '--no-mac-metadata')
14491460
subprocess.check_call(tar_cmd, cwd=root_dir,
14501461
stdout=subprocess.DEVNULL)
14511462

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)