From 0db84f5aa4459907f03a11ce87bb3e14dce96ba3 Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Tue, 23 Jan 2024 07:07:30 -0500 Subject: [PATCH] rules: write empty file if there are no rules to save --- lib/logitech_receiver/diversion.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/logitech_receiver/diversion.py b/lib/logitech_receiver/diversion.py index 4dee89f3dd..8afaf97fd0 100644 --- a/lib/logitech_receiver/diversion.py +++ b/lib/logitech_receiver/diversion.py @@ -1545,7 +1545,8 @@ def convert(elem): _log.info('saving %d rule(s) to %s', len(rules_to_save), file_name) try: 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) except Exception as e: _log.error('failed to save to %s\n%s', file_name, e)