misc: fix mkdir race condition in thumbnails (#58852)
gitea-wip/wcs/pipeline/head Build started...
Details
gitea-wip/wcs/pipeline/head Build started...
Details
This commit is contained in:
parent
782ec1b8ba
commit
92d7530f83
|
@ -273,10 +273,14 @@ def test_thumbnail_caching(pub):
|
|||
thumb_filepath = os.path.join(
|
||||
thumbs_dir, hashlib.sha256(force_bytes(data_file.get_fs_filename())).hexdigest()
|
||||
)
|
||||
assert os.path.exists(thumbs_dir) is False
|
||||
assert os.path.exists(thumb_filepath) is False
|
||||
admin_app = login(get_app(pub), username='admin', password='admin')
|
||||
admin_app.get('/backoffice/management/test/1/download?f=0&thumbnail=1').follow()
|
||||
assert os.path.exists(thumbs_dir) is True
|
||||
assert os.path.exists(thumb_filepath) is True
|
||||
# again, thumbs_dir already exists
|
||||
admin_app.get('/backoffice/management/test/1/download?f=0&thumbnail=1').follow()
|
||||
|
||||
|
||||
@mock.patch('wcs.wscalls.call_webservice')
|
||||
|
|
|
@ -681,8 +681,10 @@ def get_thumbnail(filepath, content_type=None):
|
|||
|
||||
# check if thumbnail already exists
|
||||
thumbs_dir = os.path.join(get_publisher().app_dir, 'thumbs')
|
||||
if not os.path.exists(thumbs_dir):
|
||||
try:
|
||||
os.mkdir(thumbs_dir)
|
||||
except FileExistsError:
|
||||
pass
|
||||
thumb_filepath = os.path.join(thumbs_dir, hashlib.sha256(force_bytes(filepath)).hexdigest())
|
||||
if os.path.exists(thumb_filepath):
|
||||
with open(thumb_filepath, 'rb') as f:
|
||||
|
|
Loading…
Reference in New Issue