Do not keep a new file if we fail to set its attributes.
This commit is contained in:
parent
4094edf92f
commit
17665d962b
1 changed files with 10 additions and 2 deletions
12
files/file
12
files/file
|
@ -331,8 +331,16 @@ def main():
|
||||||
module.fail_json(path=path, msg='Error while touching existing target: %s' % str(e))
|
module.fail_json(path=path, msg='Error while touching existing target: %s' % str(e))
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg='Cannot touch other than files and directories')
|
module.fail_json(msg='Cannot touch other than files and directories')
|
||||||
|
try:
|
||||||
module.set_fs_attributes_if_different(file_args, True)
|
module.set_fs_attributes_if_different(file_args, True)
|
||||||
|
except SystemExit as e:
|
||||||
|
if e.code:
|
||||||
|
# We take this to mean that fail_json() was called from
|
||||||
|
# somewhere in basic.py
|
||||||
|
if prev_state == 'absent':
|
||||||
|
# If we just created the file we can safely remove it
|
||||||
|
os.remove(path)
|
||||||
|
raise e
|
||||||
|
|
||||||
module.exit_json(dest=path, changed=True)
|
module.exit_json(dest=path, changed=True)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue