mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-13 11:49:11 -07:00
created makedirs_safe function for use in cases of multiprocess
should fix #11126 and most race conditions
This commit is contained in:
parent
47be5b4166
commit
2590df6df1
5 changed files with 23 additions and 15 deletions
|
@ -19,6 +19,7 @@ __metaclass__ = type
|
|||
|
||||
import os
|
||||
import stat
|
||||
from time import sleep
|
||||
|
||||
__all__ = ['is_executable', 'unfrackpath']
|
||||
|
||||
|
@ -35,3 +36,12 @@ def unfrackpath(path):
|
|||
'''
|
||||
return os.path.normpath(os.path.realpath(os.path.expandvars(os.path.expanduser(path))))
|
||||
|
||||
def makedirs_safe(path, mode=None):
|
||||
'''Safe way to create dirs in muliprocess/thread environments'''
|
||||
while not os.path.exists(path):
|
||||
try:
|
||||
os.makedirs(path, mode)
|
||||
except OSError, e:
|
||||
if e.errno != 17:
|
||||
raise
|
||||
sleep(1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue