[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 dd2ebdf89f)

Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
This commit is contained in:
Miss Islington (bot) 2023-12-10 19:49:39 +01:00 committed by GitHub
parent c108080626
commit 68657e2b73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View file

@ -1615,6 +1615,17 @@ def test_tarfile_vs_tar(self):
# now create another tarball using `tar`
tarball2 = os.path.join(root_dir, 'archive2.tar')
tar_cmd = ['tar', '-cf', 'archive2.tar', base_dir]
if sys.platform == 'darwin':
# macOS tar can include extended attributes,
# ACLs and other mac specific metadata into the
# archive (an recentish version of the OS).
#
# This feature can be disabled with the
# '--no-mac-metadata' option on macOS 11 or
# later.
import platform
if int(platform.mac_ver()[0].split('.')[0]) >= 11:
tar_cmd.insert(1, '--no-mac-metadata')
subprocess.check_call(tar_cmd, cwd=root_dir,
stdout=subprocess.DEVNULL)

View file

@ -0,0 +1,2 @@
Fix ``test_tarfile_vs_tar`` in ``test_shutil`` for macOS, where system tar
can include more information in the archive than :mod:`shutil.make_archive`.