From a155eefa23ff31ec48a49168d052896e60204bcf Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sat, 6 Jun 2020 14:30:04 -0700 Subject: [PATCH] Fix for certain configuration options like ssh_command impacting Borg invocations for separate configuration files (#323). --- NEWS | 2 ++ borgmatic/borg/environment.py | 2 ++ tests/unit/borg/test_environment.py | 12 ++++++++++++ 3 files changed, 16 insertions(+) diff --git a/NEWS b/NEWS index 09a76063f..129c9789a 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ still trigger a monitoring "fail" status. * #316: Fix hang when a stale database dump named pipe from an aborted borgmatic run remains on disk. + * #323: Fix for certain configuration options like ssh_command impacting Borg invocations for + separate configuration files. * Tweak comment indentation in generated configuration file for clarity. * Link to Borgmacator GNOME AppIndicator from monitoring documentation. diff --git a/borgmatic/borg/environment.py b/borgmatic/borg/environment.py index 728726907..7c166db37 100644 --- a/borgmatic/borg/environment.py +++ b/borgmatic/borg/environment.py @@ -22,6 +22,8 @@ def initialize(storage_config): value = storage_config.get(option_name) if value: os.environ[environment_variable_name] = value + else: + os.environ.pop(environment_variable_name, None) for ( option_name, diff --git a/tests/unit/borg/test_environment.py b/tests/unit/borg/test_environment.py index 075d9929c..9c49e4a1d 100644 --- a/tests/unit/borg/test_environment.py +++ b/tests/unit/borg/test_environment.py @@ -60,3 +60,15 @@ def test_initialize_with_relocated_repo_access_should_override_default(): assert os.environ.get('BORG_RELOCATED_REPO_ACCESS_IS_OK') == 'yes' finally: os.environ = orig_environ + + +def test_initialize_is_not_effected_by_existing_environment(): + orig_environ = os.environ + + try: + os.environ = {'BORG_PASSPHRASE': 'pass', 'BORG_SSH': 'mosh'} + module.initialize({'ssh_command': 'ssh -C'}) + assert 'BORG_PASSPHRASE' not in os.environ + assert os.environ.get('BORG_RSH') == 'ssh -C' + finally: + os.environ = orig_environ