Fix an error when running "borg key export" through borgmatic (#719).

This commit is contained in:
Dan Helfman 2023-06-26 09:30:46 -07:00
parent c3004c6090
commit b242078f54
4 changed files with 24 additions and 4 deletions

3
NEWS
View file

@ -1,3 +1,6 @@
1.7.16.dev0
* #719: Fix an error when running "borg key export" through borgmatic.
1.7.15
* #326: Add configuration options and command-line flags for backing up a database from one
location while restoring it somewhere else.

View file

@ -216,15 +216,21 @@ def parse_arguments_for_actions(unparsed_arguments, action_parsers, global_parse
arguments['global'], remaining = global_parser.parse_known_args(unparsed_arguments)
remaining_action_arguments.append(remaining)
# Prevent action names that follow "--config" paths from being considered as additional paths.
# Prevent action names and arguments that follow "--config" paths from being considered as
# additional paths.
for argument_name in arguments.keys():
if argument_name == 'global':
continue
for action_name in [argument_name] + ACTION_ALIASES.get(argument_name, []):
if action_name in arguments['global'].config_paths:
arguments['global'].config_paths.remove(action_name)
try:
action_name_index = arguments['global'].config_paths.index(action_name)
arguments['global'].config_paths = arguments['global'].config_paths[
:action_name_index
]
break
except ValueError:
pass
return (
arguments,

View file

@ -1,6 +1,6 @@
from setuptools import find_packages, setup
VERSION = '1.7.15'
VERSION = '1.7.16.dev0'
setup(

View file

@ -52,6 +52,17 @@ def test_parse_arguments_with_action_after_config_path_omits_aliased_action():
assert arguments['rcreate'].encryption_mode == 'repokey'
def test_parse_arguments_with_action_and_positional_arguments_after_config_path_omits_action_and_arguments():
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
arguments = module.parse_arguments('--config', 'myconfig', 'borg', 'key', 'export')
global_arguments = arguments['global']
assert global_arguments.config_paths == ['myconfig']
assert 'borg' in arguments
assert arguments['borg'].options == ['key', 'export']
def test_parse_arguments_with_verbosity_overrides_default():
config_paths = ['default']
flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths)