Skip to content

Commit 35f2bb9

Browse files
authored
gh-162963: Fix test_tarfile_vs_tar on Windows (#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.
1 parent cd023a7 commit 35f2bb9

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
@@ -1942,7 +1942,10 @@ def test_tarfile_vs_tar(self):
19421942

19431943
# now create another tarball using `tar`
19441944
tarball2 = os.path.join(root_dir, 'archive2.tar')
1945-
tar_cmd = ['tar', '-cf', 'archive2.tar', base_dir]
1945+
# Write the archive to stdout: bsdtar on Windows can wrongly skip
1946+
# directories with "Can't add archive to itself" when writing to
1947+
# a regular file.
1948+
tar_cmd = ['tar', '-cf', '-', base_dir]
19461949
if sys.platform == 'darwin':
19471950
# macOS tar can include extended attributes,
19481951
# ACLs and other mac specific metadata into the
@@ -1954,8 +1957,9 @@ def test_tarfile_vs_tar(self):
19541957
import platform
19551958
if int(platform.mac_ver()[0].split('.')[0]) >= 11:
19561959
tar_cmd.insert(1, '--no-mac-metadata')
1957-
subprocess.check_call(tar_cmd, cwd=root_dir,
1958-
stdout=subprocess.DEVNULL)
1960+
data = subprocess.check_output(tar_cmd, cwd=root_dir)
1961+
with open(tarball2, 'wb') as f:
1962+
f.write(data)
19591963

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

0 commit comments

Comments
 (0)