From 874213aef9e454fd8d2e6234d01a8edbb85d6ea1 Mon Sep 17 00:00:00 2001 From: gryf Date: Sat, 20 Mar 2021 13:12:58 +0100 Subject: [PATCH] Prevent from nonexistent paths in config. In case of defining paths in config, which wrapper is trying to normalize, sometimes it may happen, that paths can be either local or remote - depending on the intention, i.e. one can add: cdrom_drive_0: foo.iso where foo can be either an unpacked file or just some companion image, which exists within config file. In this patch calculated path is checked against file existence, and if it doesn't exists, original value is preserved. --- fs_uae_wrapper/base.py | 6 +++++- fs_uae_wrapper/utils.py | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/fs_uae_wrapper/base.py b/fs_uae_wrapper/base.py index d89e496..a4323ed 100644 --- a/fs_uae_wrapper/base.py +++ b/fs_uae_wrapper/base.py @@ -219,7 +219,11 @@ class Base(object): changed_options[key] = abspath continue - changed_options[key] = os.path.abspath(val) + _val = os.path.abspath(val) + if os.path.exists(_val): + changed_options[key] = _val + else: + changed_options[key] = val self.fsuae_options.update(changed_options) diff --git a/fs_uae_wrapper/utils.py b/fs_uae_wrapper/utils.py index 583687f..1e19dbc 100644 --- a/fs_uae_wrapper/utils.py +++ b/fs_uae_wrapper/utils.py @@ -144,6 +144,7 @@ def interpolate_variables(string, config_path, base=None): - $BASE """ + _string = string if '$CONFIG' in string: conf_path = os.path.dirname(os.path.abspath(config_path)) string = os.path.abspath(string.replace('$CONFIG', conf_path)) @@ -166,7 +167,9 @@ def interpolate_variables(string, config_path, base=None): if '$BASE' in string: string = string.replace('$BASE', base) - return string + if os.path.exists(string): + return string + return _string def get_config(conf_file):