rules: write empty file if there are no rules to save

This commit is contained in:
Peter F. Patel-Schneider 2024-01-23 07:07:30 -05:00
parent f8a462dbe5
commit 0db84f5aa4
1 changed files with 2 additions and 1 deletions

View File

@ -1545,7 +1545,8 @@ def _save_config_rule_file(file_name=_file_path):
_log.info('saving %d rule(s) to %s', len(rules_to_save), file_name) _log.info('saving %d rule(s) to %s', len(rules_to_save), file_name)
try: try:
with open(file_name, 'w') as f: with open(file_name, 'w') as f:
f.write('%YAML 1.3\n') # Write version manually if rules_to_save:
f.write('%YAML 1.3\n') # Write version manually
_yaml_dump_all(convert([r['Rule'] for r in rules_to_save]), f, **dump_settings) _yaml_dump_all(convert([r['Rule'] for r in rules_to_save]), f, **dump_settings)
except Exception as e: except Exception as e:
_log.error('failed to save to %s\n%s', file_name, e) _log.error('failed to save to %s\n%s', file_name, e)