From cd80c941ada89233da17e7c1f2fe1f4d05821740 Mon Sep 17 00:00:00 2001 From: Fuxino Date: Thu, 8 Oct 2026 20:42:05 +0200 Subject: [PATCH] Treat empty SSH settings in the config as not set The example config has empty remote_sudo and numeric_ids values, which made getboolean fail with "Bad configuration file" if the [server] section was uncommented, and an empty ssh_keyfile was used as the key path. Treat empty values as false or not set, and show false in the example config. --- simple_backup/simple_backup.conf | 4 ++-- simple_backup/simple_backup.py | 26 +++++++------------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/simple_backup/simple_backup.conf b/simple_backup/simple_backup.conf index 0cbdb66..1cd91b0 100644 --- a/simple_backup/simple_backup.conf +++ b/simple_backup/simple_backup.conf @@ -18,5 +18,5 @@ keep=-1 # ssh_host= # ssh_user= # ssh_keyfile= -# remote_sudo= -# numeric_ids= +# remote_sudo=false +# numeric_ids=false diff --git a/simple_backup/simple_backup.py b/simple_backup/simple_backup.py index a595373..14b1f2e 100755 --- a/simple_backup/simple_backup.py +++ b/simple_backup/simple_backup.py @@ -849,26 +849,14 @@ def _read_config(config_file, user: Optional[str] = None): config_args['ssh_host'] = config.get('server', 'ssh_host', fallback='').strip() or None config_args['ssh_user'] = config.get('server', 'ssh_user', fallback='').strip() or None - try: - ssh_keyfile = config.get('server', 'ssh_keyfile') - except (configparser.NoSectionError, configparser.NoOptionError): - ssh_keyfile = None + config_args['ssh_keyfile'] = config.get('server', 'ssh_keyfile', fallback='').strip() or None - config_args['ssh_keyfile'] = ssh_keyfile - - try: - remote_sudo = config.getboolean('server', 'remote_sudo') - except (configparser.NoSectionError, configparser.NoOptionError): - remote_sudo = False - - config_args['remote_sudo'] = remote_sudo - - try: - numeric_ids = config.getboolean('server', 'numeric_ids') - except (configparser.NoSectionError, configparser.NoOptionError): - numeric_ids = False - - config_args['numeric_ids'] = numeric_ids + # Empty values (as in the example config) count as false + for key in ['remote_sudo', 'numeric_ids']: + if config.get('server', key, fallback='').strip() == '': + config_args[key] = False + else: + config_args[key] = config.getboolean('server', key) return config_args