mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #28545 from jfindlay/concurrent_dir
pass on concurrent create of jid_dir in local_cache
This commit is contained in:
commit
e048667c91
2 changed files with 16 additions and 2 deletions
|
@ -19,6 +19,7 @@ from __future__ import absolute_import
|
|||
|
||||
# Import python libs
|
||||
import os
|
||||
import errno
|
||||
import logging
|
||||
|
||||
# Import salt libs
|
||||
|
@ -232,8 +233,13 @@ def file_hash(load, fnd):
|
|||
if not os.path.exists(cache_dir):
|
||||
try:
|
||||
os.makedirs(cache_dir)
|
||||
except OSError:
|
||||
pass
|
||||
except OSError as err:
|
||||
if err.errno == errno.EEXIST:
|
||||
# rarely, the directory can be already concurrently created between
|
||||
# the os.path.exists and the os.makedirs lines above
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
# save the cache object "hash:mtime"
|
||||
cache_object = '{0}:{1}'.format(ret['hsum'], os.path.getmtime(path))
|
||||
with salt.utils.flopen(cache_path, 'w') as fp_:
|
||||
|
|
|
@ -185,6 +185,14 @@ def save_load(jid, clear_load):
|
|||
try:
|
||||
if not os.path.exists(jid_dir):
|
||||
os.makedirs(jid_dir)
|
||||
except OSError as exc:
|
||||
if exc.errno == errno.EEXIST:
|
||||
# rarely, the directory can be already concurrently created between
|
||||
# the os.path.exists and the os.makedirs lines above
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
try:
|
||||
serial.dump(
|
||||
clear_load,
|
||||
salt.utils.fopen(os.path.join(jid_dir, LOAD_P), 'w+b')
|
||||
|
|
Loading…
Add table
Reference in a new issue