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.
This commit is contained in:
Fuxino
2026-10-08 20:42:05 +02:00
parent 29958896a2
commit cd80c941ad
2 changed files with 9 additions and 21 deletions
+2 -2
View File
@@ -18,5 +18,5 @@ keep=-1
# ssh_host=
# ssh_user=
# ssh_keyfile=
# remote_sudo=
# numeric_ids=
# remote_sudo=false
# numeric_ids=false
+7 -19
View File
@@ -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