Fixes #79587: Improve style

pull/83111/head
pinrada 1 month ago
parent ed040fb6a7
commit c1e692934d

@ -528,24 +528,24 @@ def ensure_absent(path):
prev_state = get_state(b_path) prev_state = get_state(b_path)
result = {} result = {}
file_args = module.load_file_common_arguments(module.params) file_args = module.load_file_common_arguments(module.params)
changed = False changed = False
if prev_state != 'absent': if prev_state != 'absent':
diff = initial_diff(path, 'absent', prev_state) diff = initial_diff(path, 'absent', prev_state)
if not module.check_mode: if not module.check_mode:
if prev_state == 'directory': if prev_state == 'directory':
# Check if 'attributes' in file_args # Check if 'attributes' in file_args
current_attributes = file_args.get('attributes', '') current_attributes = file_args.get('attributes', '')
if '-a' in current_attributes: if '-a' in current_attributes:
# Attempt to remove the append-only attribute before deletion # Attempt to remove the append-only attribute before deletion
try: try:
module.set_attributes_if_different(path, current_attributes, changed, module.set_attributes_if_different(path, current_attributes, changed,
diff, expand=False) diff, expand=False)
changed = True # Mark as changed if attributes were modified changed = True # Mark as changed if attributes were modified
except Exception as e: except Exception as e:
module.fail_json(msg="Failed to change attributes: %s" % to_native(e), module.fail_json(msg="Failed to change attributes: %s" % to_native(e),
path=to_native(b_path)) path=to_native(b_path))
try: try:
shutil.rmtree(b_path, ignore_errors=False) shutil.rmtree(b_path, ignore_errors=False)
except Exception as e: except Exception as e:

Loading…
Cancel
Save