1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Do not keep a new file if we fail to set its attributes.

This commit is contained in:
Toshio Kuratomi 2014-09-15 12:34:16 -07:00
parent cdf938f2c2
commit a44ea2d1b7

View file

@ -331,8 +331,16 @@ def main():
module.fail_json(path=path, msg='Error while touching existing target: %s' % str(e))
else:
module.fail_json(msg='Cannot touch other than files and directories')
module.set_fs_attributes_if_different(file_args, True)
try:
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)