mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
fix path utils
This commit is contained in:
parent
b75fccb475
commit
bae988ee9b
1 changed files with 7 additions and 5 deletions
|
@ -22,7 +22,7 @@ from errno import EEXIST
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.utils.unicode import to_bytes, to_str
|
from ansible.utils.unicode import to_bytes, to_str
|
||||||
|
|
||||||
__all__ = ['unfrackpath']
|
__all__ = ['unfrackpath', 'makedirs_safe']
|
||||||
|
|
||||||
def unfrackpath(path):
|
def unfrackpath(path):
|
||||||
'''
|
'''
|
||||||
|
@ -35,12 +35,14 @@ def unfrackpath(path):
|
||||||
|
|
||||||
def makedirs_safe(path, mode=None):
|
def makedirs_safe(path, mode=None):
|
||||||
'''Safe way to create dirs in muliprocess/thread environments'''
|
'''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:
|
try:
|
||||||
if mode:
|
if mode:
|
||||||
os.makedirs(path, mode)
|
os.makedirs(rpath, mode)
|
||||||
else:
|
else:
|
||||||
os.makedirs(path)
|
os.makedirs(rpath)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno != EEXIST:
|
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…
Reference in a new issue