]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109980: Fix test_tarfile_vs_tar on macOS (#112905)
authorRonald Oussoren <ronaldoussoren@mac.com>
Sun, 10 Dec 2023 11:38:49 +0000 (12:38 +0100)
committerGitHub <noreply@github.com>
Sun, 10 Dec 2023 11:38:49 +0000 (12:38 +0100)
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.

Lib/test/test_shutil.py
Misc/NEWS.d/next/Tests/2023-12-09-21-27-46.gh-issue-109980.y--500.rst [new file with mode: 0644]

index d7061b2f9d87249b227bc82c396951e9ecf94fce..b29d316352f219e423fa3a540572c6eafa930404 100644 (file)
@@ -1670,6 +1670,17 @@ class TestArchives(BaseTest, unittest.TestCase):
         # 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)
 
diff --git a/Misc/NEWS.d/next/Tests/2023-12-09-21-27-46.gh-issue-109980.y--500.rst b/Misc/NEWS.d/next/Tests/2023-12-09-21-27-46.gh-issue-109980.y--500.rst
new file mode 100644 (file)
index 0000000..c475a33
--- /dev/null
@@ -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`.