Skip to content

Commit 0e88df1

Browse files
[3.15] gh-162963: Fix test_tarfile_vs_tar on Windows (GH-162998) (#163002)
gh-162963: Fix test_tarfile_vs_tar on Windows (GH-162998) bsdtar on Windows sometimes wrongly skips a directory with "Can't add archive to itself" when writing the archive to a regular file. Write the archive to stdout instead, so the check is not done. (cherry picked from commit 35f2bb9) Co-authored-by: Andrew Svetlov <[email protected]>
1 parent eb25938 commit 0e88df1

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎Lib/test/test_shutil.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,10 @@ def test_tarfile_vs_tar(self):
18251825

18261826
# now create another tarball using `tar`
18271827
tarball2 = os.path.join(root_dir, 'archive2.tar')
1828-
tar_cmd = ['tar', '-cf', 'archive2.tar', base_dir]
1828+
# Write the archive to stdout: bsdtar on Windows can wrongly skip
1829+
# directories with "Can't add archive to itself" when writing to
1830+
# a regular file.
1831+
tar_cmd = ['tar', '-cf', '-', base_dir]
18291832
if sys.platform == 'darwin':
18301833
# macOS tar can include extended attributes,
18311834
# ACLs and other mac specific metadata into the
@@ -1837,8 +1840,9 @@ def test_tarfile_vs_tar(self):
18371840
import platform
18381841
if int(platform.mac_ver()[0].split('.')[0]) >= 11:
18391842
tar_cmd.insert(1, '--no-mac-metadata')
1840-
subprocess.check_call(tar_cmd, cwd=root_dir,
1841-
stdout=subprocess.DEVNULL)
1843+
data = subprocess.check_output(tar_cmd, cwd=root_dir)
1844+
with open(tarball2, 'wb') as f:
1845+
f.write(data)
18421846

18431847
self.assertTrue(os.path.isfile(tarball2))
18441848
# let's compare both tarballs

0 commit comments

Comments
 (0)