fix path utils

pull/16316/head
Brian Coca 9 years ago
parent b75fccb475
commit bae988ee9b

@ -22,7 +22,7 @@ from errno import EEXIST
from ansible.errors import AnsibleError
from ansible.utils.unicode import to_bytes, to_str
__all__ = ['unfrackpath']
__all__ = ['unfrackpath', 'makedirs_safe']
def unfrackpath(path):
'''
@ -35,12 +35,14 @@ def unfrackpath(path):
def makedirs_safe(path, mode=None):
'''Safe way to create dirs in muliprocess/thread environments'''
if not os.path.exists(to_bytes(path, errors='strict')):
rpath = unfrackpath(path)
if not os.path.exists(to_bytes(rpath, errors='strict')):
try:
if mode:
os.makedirs(path, mode)
os.makedirs(rpath, mode)
else:
os.makedirs(path)
os.makedirs(rpath)
except OSError as e:
if e.errno != EEXIST:
raise AnsibleError("Unable to create local directories(%s): %s" % (path, to_str(e)))
raise AnsibleError("Unable to create local directories(%s): %s" % (rpath, to_str(e)))

Loading…
Cancel
Save