From 8a2514915c3027f0febcb1b4691722168a2c0aea Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sat, 22 Jul 2023 15:25:55 -0700 Subject: [PATCH] Fix for Borg's interactive prompt on the "check --repair" action automatically getting answered "NO" (#730). --- NEWS | 2 ++ borgmatic/borg/check.py | 2 +- borgmatic/borg/environment.py | 10 ++++++---- borgmatic/config/schema.yaml | 8 ++++---- tests/unit/borg/test_environment.py | 24 ++++++++++++++++-------- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index 94f6993..4b8dcb3 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,7 @@ 1.8.1.dev0 * #728: Fix for "prune" action error when using the "keep_exclude_tags" option in configuration. + * #730: Fix for Borg's interactive prompt on the "check --repair" action automatically getting + answered "NO" even when the "check_i_know_what_i_am_doing" option isn't set. 1.8.0 * #575: BREAKING: For the "borgmatic borg" action, instead of implicitly injecting diff --git a/borgmatic/borg/check.py b/borgmatic/borg/check.py index 859052b..eabbdd3 100644 --- a/borgmatic/borg/check.py +++ b/borgmatic/borg/check.py @@ -142,7 +142,7 @@ def filter_checks_on_frequency( if datetime.datetime.now() < check_time + frequency_delta: remaining = check_time + frequency_delta - datetime.datetime.now() logger.info( - f'Skipping {check} check due to configured frequency; {remaining} until next check' + f'Skipping {check} check due to configured frequency; {remaining} until next check (use --force to check anyway)' ) filtered_checks.remove(check) diff --git a/borgmatic/borg/environment.py b/borgmatic/borg/environment.py index fbe99b6..6c7b6e7 100644 --- a/borgmatic/borg/environment.py +++ b/borgmatic/borg/environment.py @@ -38,14 +38,16 @@ def make_environment(config): option_name, environment_variable_name, ) in DEFAULT_BOOL_OPTION_TO_DOWNCASE_ENVIRONMENT_VARIABLE.items(): - value = config.get(option_name, False) - environment[environment_variable_name] = 'yes' if value else 'no' + value = config.get(option_name) + if value is not None: + environment[environment_variable_name] = 'yes' if value else 'no' for ( option_name, environment_variable_name, ) in DEFAULT_BOOL_OPTION_TO_UPPERCASE_ENVIRONMENT_VARIABLE.items(): - value = config.get(option_name, False) - environment[environment_variable_name] = 'YES' if value else 'NO' + value = config.get(option_name) + if value is not None: + environment[environment_variable_name] = 'YES' if value else 'NO' return environment diff --git a/borgmatic/config/schema.yaml b/borgmatic/config/schema.yaml index 59e8856..f5eb001 100644 --- a/borgmatic/config/schema.yaml +++ b/borgmatic/config/schema.yaml @@ -365,19 +365,19 @@ properties: type: boolean description: | Bypass Borg error about a repository that has been moved. Defaults - to false. + to not bypassing. example: true unknown_unencrypted_repo_access_is_ok: type: boolean description: | Bypass Borg error about a previously unknown unencrypted repository. - Defaults to false. + Defaults to not bypassing. example: true check_i_know_what_i_am_doing: type: boolean description: | - Bypass Borg confirmation about check with repair option. - Defaults to false. + Bypass Borg confirmation about check with repair option. Defaults to + an interactive prompt from Borg. example: true extra_borg_options: type: object diff --git a/tests/unit/borg/test_environment.py b/tests/unit/borg/test_environment.py index 203a6b0..cf42687 100644 --- a/tests/unit/borg/test_environment.py +++ b/tests/unit/borg/test_environment.py @@ -19,28 +19,36 @@ def test_make_environment_with_ssh_command_should_set_environment(): assert environment.get('BORG_RSH') == 'ssh -C' -def test_make_environment_without_configuration_should_only_set_default_environment(): +def test_make_environment_without_configuration_should_not_set_environment(): environment = module.make_environment({}) - assert environment == { - 'BORG_RELOCATED_REPO_ACCESS_IS_OK': 'no', - 'BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK': 'no', - 'BORG_CHECK_I_KNOW_WHAT_I_AM_DOING': 'NO', - } + assert environment == {} -def test_make_environment_with_relocated_repo_access_should_override_default(): +def test_make_environment_with_relocated_repo_access_true_should_set_environment_yes(): environment = module.make_environment({'relocated_repo_access_is_ok': True}) assert environment.get('BORG_RELOCATED_REPO_ACCESS_IS_OK') == 'yes' -def test_make_environment_check_i_know_what_i_am_doing_should_override_default(): +def test_make_environment_with_relocated_repo_access_false_should_set_environment_no(): + environment = module.make_environment({'relocated_repo_access_is_ok': False}) + + assert environment.get('BORG_RELOCATED_REPO_ACCESS_IS_OK') == 'no' + + +def test_make_environment_check_i_know_what_i_am_doing_true_should_set_environment_YES(): environment = module.make_environment({'check_i_know_what_i_am_doing': True}) assert environment.get('BORG_CHECK_I_KNOW_WHAT_I_AM_DOING') == 'YES' +def test_make_environment_check_i_know_what_i_am_doing_false_should_set_environment_NO(): + environment = module.make_environment({'check_i_know_what_i_am_doing': False}) + + assert environment.get('BORG_CHECK_I_KNOW_WHAT_I_AM_DOING') == 'NO' + + def test_make_environment_with_integer_variable_value(): environment = module.make_environment({'borg_files_cache_ttl': 40}) assert environment.get('BORG_FILES_CACHE_TTL') == '40'