Skip to content

Commit

Permalink
Fixes ansible#79587: Adds a call to function set_attributes_if_differ…
Browse files Browse the repository at this point in the history
…ent to ensure_absent
  • Loading branch information
pinradaThan committed Apr 20, 2024
1 parent 6ab97c0 commit ed040fb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/ansible/modules/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from __future__ import annotations


DOCUMENTATION = r'''
---
module: file
Expand Down Expand Up @@ -539,16 +540,16 @@ def ensure_absent(path):
if '-a' in current_attributes:
# Attempt to remove the append-only attribute before deletion
try:
module.set_attributes_if_different(path, current_attributes, changed, diff, expand=False)
module.set_attributes_if_different(path, current_attributes, changed,
diff, expand=False)
changed = True # Mark as changed if attributes were modified
except Exception as e:
module.fail_json(msg="Failed to change attributes: %s" % to_native(e), path=to_native(b_path))
module.fail_json(msg="Failed to change attributes: %s" % to_native(e),
path=to_native(b_path))
try:
shutil.rmtree(b_path, ignore_errors=False)
except Exception as e:
# raise AnsibleModuleError(results={'msg': "rmtree failed: %s" % to_native(e)})
raise AnsibleModuleError(results={'msg': "rmtree failed: %s" % to_native(e),
'details': "Attributes before removal: %s, Changed: %s" % (file_args.get('attributes', 'None'), changed)})
raise AnsibleModuleError(results={'msg': "rmtree failed: %s" % to_native(e)})
else:
try:
os.unlink(b_path)
Expand Down

0 comments on commit ed040fb

Please sign in to comment.