mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 05:10:22 -07:00
Ensure remove files work when file was already removed
If a file disappears when you are removing it, this will ensure it doesn't fail and continues as expected.
This commit is contained in:
parent
f3399a5e34
commit
6a08b16c37
1 changed files with 8 additions and 3 deletions
|
@ -281,8 +281,9 @@ def main():
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
os.unlink(b_path)
|
os.unlink(b_path)
|
||||||
except Exception as e:
|
except OSError as e:
|
||||||
module.fail_json(path=path, msg="unlinking failed: %s " % to_native(e))
|
if e.errno != errno.ENOENT: # It may already have been removed
|
||||||
|
module.fail_json(path=path, msg="unlinking failed: %s " % to_native(e))
|
||||||
module.exit_json(path=path, changed=True, diff=diff)
|
module.exit_json(path=path, changed=True, diff=diff)
|
||||||
else:
|
else:
|
||||||
module.exit_json(path=path, changed=False)
|
module.exit_json(path=path, changed=False)
|
||||||
|
@ -415,7 +416,11 @@ def main():
|
||||||
os.rmdir(b_path)
|
os.rmdir(b_path)
|
||||||
elif prev_state == 'directory' and state == 'hard':
|
elif prev_state == 'directory' and state == 'hard':
|
||||||
if os.path.exists(b_path):
|
if os.path.exists(b_path):
|
||||||
os.remove(b_path)
|
try:
|
||||||
|
os.unlink(b_path)
|
||||||
|
except OSError as e:
|
||||||
|
if e.errno != errno.ENOENT: # It may already have been removed
|
||||||
|
raise
|
||||||
if state == 'hard':
|
if state == 'hard':
|
||||||
os.link(b_src, b_tmppath)
|
os.link(b_src, b_tmppath)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue