mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-67837, gh-112998: Fix dirs creation in concurrent extraction (GH-115082)
Avoid race conditions in the creation of directories during concurrent extraction in tarfile and zipfile. Co-authored-by: Samantha Hughes <shughes-uk@users.noreply.github.com> Co-authored-by: Peder Bergebakken Sundt <pbsds@hotmail.com>
This commit is contained in:
parent
bf75f1b147
commit
5d2794a16b
4 changed files with 31 additions and 3 deletions
|
@ -3,6 +3,7 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
from test.support import swap_attr
|
||||
from test.support import os_helper
|
||||
|
||||
class OverwriteTests:
|
||||
|
@ -153,3 +154,24 @@ class OverwriteTests:
|
|||
self.extractall(ar)
|
||||
self.assertTrue(os.path.islink(target))
|
||||
self.assertFalse(os.path.exists(target2))
|
||||
|
||||
def test_concurrent_extract_dir(self):
|
||||
target = os.path.join(self.testdir, 'test')
|
||||
def concurrent_mkdir(*args, **kwargs):
|
||||
orig_mkdir(*args, **kwargs)
|
||||
orig_mkdir(*args, **kwargs)
|
||||
with swap_attr(os, 'mkdir', concurrent_mkdir) as orig_mkdir:
|
||||
with self.open(self.ar_with_dir) as ar:
|
||||
self.extractall(ar)
|
||||
self.assertTrue(os.path.isdir(target))
|
||||
|
||||
def test_concurrent_extract_implicit_dir(self):
|
||||
target = os.path.join(self.testdir, 'test')
|
||||
def concurrent_mkdir(*args, **kwargs):
|
||||
orig_mkdir(*args, **kwargs)
|
||||
orig_mkdir(*args, **kwargs)
|
||||
with swap_attr(os, 'mkdir', concurrent_mkdir) as orig_mkdir:
|
||||
with self.open(self.ar_with_implicit_dir) as ar:
|
||||
self.extractall(ar)
|
||||
self.assertTrue(os.path.isdir(target))
|
||||
self.assertTrue(os.path.isfile(os.path.join(target, 'file')))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue