mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
created makedirs_safe function for use in cases of multiprocess
should fix #11126 and most race conditions
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user