now captures any exceptions when trying to create directories
This commit is contained in:
parent
54b02ee0da
commit
e4dd0d98d4
1 changed files with 24 additions and 20 deletions
|
@ -271,26 +271,30 @@ def main():
|
||||||
module.exit_json(changed=True)
|
module.exit_json(changed=True)
|
||||||
changed = True
|
changed = True
|
||||||
curpath = ''
|
curpath = ''
|
||||||
# Split the path so we can apply filesystem attributes recursively
|
|
||||||
# from the root (/) directory for absolute paths or the base path
|
try:
|
||||||
# of a relative path. We can then walk the appropriate directory
|
# Split the path so we can apply filesystem attributes recursively
|
||||||
# path to apply attributes.
|
# from the root (/) directory for absolute paths or the base path
|
||||||
for dirname in path.strip('/').split('/'):
|
# of a relative path. We can then walk the appropriate directory
|
||||||
curpath = '/'.join([curpath, dirname])
|
# path to apply attributes.
|
||||||
# Remove leading slash if we're creating a relative path
|
for dirname in path.strip('/').split('/'):
|
||||||
if not os.path.isabs(path):
|
curpath = '/'.join([curpath, dirname])
|
||||||
curpath = curpath.lstrip('/')
|
# Remove leading slash if we're creating a relative path
|
||||||
if not os.path.exists(curpath):
|
if not os.path.isabs(path):
|
||||||
try:
|
curpath = curpath.lstrip('/')
|
||||||
os.mkdir(curpath)
|
if not os.path.exists(curpath):
|
||||||
except OSError, ex:
|
try:
|
||||||
# Possibly something else created the dir since the os.path.exists
|
os.mkdir(curpath)
|
||||||
# check above. As long as it's a dir, we don't need to error out.
|
except OSError, ex:
|
||||||
if not (ex.errno == errno.EEXISTS and os.isdir(curpath)):
|
# Possibly something else created the dir since the os.path.exists
|
||||||
raise
|
# check above. As long as it's a dir, we don't need to error out.
|
||||||
tmp_file_args = file_args.copy()
|
if not (ex.errno == errno.EEXISTS and os.isdir(curpath)):
|
||||||
tmp_file_args['path']=curpath
|
raise
|
||||||
changed = module.set_fs_attributes_if_different(tmp_file_args, changed)
|
tmp_file_args = file_args.copy()
|
||||||
|
tmp_file_args['path']=curpath
|
||||||
|
changed = module.set_fs_attributes_if_different(tmp_file_args, changed)
|
||||||
|
except Exception, e:
|
||||||
|
module.fail_json(path=path, msg='There was an issue creating %s as requested: %s' % (curpath, str(e)))
|
||||||
|
|
||||||
# We already know prev_state is not 'absent', therefore it exists in some form.
|
# We already know prev_state is not 'absent', therefore it exists in some form.
|
||||||
elif prev_state != 'directory':
|
elif prev_state != 'directory':
|
||||||
|
|
Loading…
Reference in a new issue