Skip to content

Commit

Permalink
gh-109980: Fix test_tarfile_vs_tar on macOS (#112905)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ronaldoussoren authored Dec 10, 2023
1 parent 5bf7580 commit dd2ebdf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Lib/test/test_shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit dd2ebdf

Please sign in to comment.