Merge pull request #28545 from jfindlay/concurrent_dir

pass on concurrent create of jid_dir in local_cache
This commit is contained in:
Mike Place 2015-11-04 07:54:10 -07:00
commit e048667c91
2 changed files with 16 additions and 2 deletions

View file

@ -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_:

View file

@ -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')