Skip to content

Commit

Permalink
fix path utils
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoca committed Jun 28, 2016
1 parent b75fccb commit bae988e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/ansible/utils/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ansible.errors import AnsibleError
from ansible.utils.unicode import to_bytes, to_str

__all__ = ['unfrackpath']
__all__ = ['unfrackpath', 'makedirs_safe']

def unfrackpath(path):
'''
Expand All @@ -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)))

0 comments on commit bae988e

Please sign in to comment.