Fix "--archive latest" on "list" and "info" actions only working on the first of multiple configured repositories (#706).

This commit is contained in:
Dan Helfman 2023-05-30 16:53:55 -07:00
parent b222f6a60b
commit 341bd4118d
7 changed files with 34 additions and 4 deletions

2
NEWS
View file

@ -3,6 +3,8 @@
or monitoring), so not even errors are shown. or monitoring), so not even errors are shown.
* #688: Tweak archive check probing logic to use the newest timestamp found when multiple exist. * #688: Tweak archive check probing logic to use the newest timestamp found when multiple exist.
* #659: Add Borg 2 date-based matching flags to various actions for archive selection. * #659: Add Borg 2 date-based matching flags to various actions for archive selection.
* #706: Fix "--archive latest" on "list" and "info" actions only working on the first of multiple
configured repositories.
1.7.13 1.7.13
* #375: Restore particular PostgreSQL schemas from a database dump via "borgmatic restore --schema" * #375: Restore particular PostgreSQL schemas from a database dump via "borgmatic restore --schema"

View file

@ -0,0 +1,9 @@
import argparse
def update_arguments(arguments, **updates):
'''
Given an argparse.Namespace instance of command-line arguments and one or more keyword argument
updates to perform, return a copy of the arguments with those updates applied.
'''
return argparse.Namespace(**dict(vars(arguments), **updates))

View file

@ -1,6 +1,7 @@
import json import json
import logging import logging
import borgmatic.actions.arguments
import borgmatic.borg.info import borgmatic.borg.info
import borgmatic.borg.rlist import borgmatic.borg.rlist
import borgmatic.config.validate import borgmatic.config.validate
@ -29,7 +30,7 @@ def run_info(
logger.answer( logger.answer(
f'{repository.get("label", repository["path"])}: Displaying archive summary information' f'{repository.get("label", repository["path"])}: Displaying archive summary information'
) )
info_arguments.archive = borgmatic.borg.rlist.resolve_archive_name( archive_name = borgmatic.borg.rlist.resolve_archive_name(
repository['path'], repository['path'],
info_arguments.archive, info_arguments.archive,
storage, storage,
@ -42,7 +43,7 @@ def run_info(
repository['path'], repository['path'],
storage, storage,
local_borg_version, local_borg_version,
info_arguments, borgmatic.actions.arguments.update_arguments(info_arguments, archive=archive_name),
global_arguments, global_arguments,
local_path, local_path,
remote_path, remote_path,

View file

@ -1,6 +1,7 @@
import json import json
import logging import logging
import borgmatic.actions.arguments
import borgmatic.borg.list import borgmatic.borg.list
import borgmatic.config.validate import borgmatic.config.validate
@ -29,7 +30,8 @@ def run_list(
logger.answer(f'{repository.get("label", repository["path"])}: Searching archives') logger.answer(f'{repository.get("label", repository["path"])}: Searching archives')
elif not list_arguments.archive: elif not list_arguments.archive:
logger.answer(f'{repository.get("label", repository["path"])}: Listing archives') logger.answer(f'{repository.get("label", repository["path"])}: Listing archives')
list_arguments.archive = borgmatic.borg.rlist.resolve_archive_name(
archive_name = borgmatic.borg.rlist.resolve_archive_name(
repository['path'], repository['path'],
list_arguments.archive, list_arguments.archive,
storage, storage,
@ -42,7 +44,7 @@ def run_list(
repository['path'], repository['path'],
storage, storage,
local_borg_version, local_borg_version,
list_arguments, borgmatic.actions.arguments.update_arguments(list_arguments, archive=archive_name),
global_arguments, global_arguments,
local_path, local_path,
remote_path, remote_path,

View file

@ -0,0 +1,10 @@
from borgmatic.actions import arguments as module
def test_update_arguments_copies_and_updates_without_modifying_original():
original = module.argparse.Namespace(foo=1, bar=2, baz=3)
result = module.update_arguments(original, bar=7, baz=8)
assert original == module.argparse.Namespace(foo=1, bar=2, baz=3)
assert result == module.argparse.Namespace(foo=1, bar=7, baz=8)

View file

@ -9,6 +9,9 @@ def test_run_info_does_not_raise():
flexmock(module.borgmatic.borg.rlist).should_receive('resolve_archive_name').and_return( flexmock(module.borgmatic.borg.rlist).should_receive('resolve_archive_name').and_return(
flexmock() flexmock()
) )
flexmock(module.borgmatic.actions.arguments).should_receive('update_arguments').and_return(
flexmock()
)
flexmock(module.borgmatic.borg.info).should_receive('display_archives_info') flexmock(module.borgmatic.borg.info).should_receive('display_archives_info')
info_arguments = flexmock(repository=flexmock(), archive=flexmock(), json=flexmock()) info_arguments = flexmock(repository=flexmock(), archive=flexmock(), json=flexmock())

View file

@ -9,6 +9,9 @@ def test_run_list_does_not_raise():
flexmock(module.borgmatic.borg.rlist).should_receive('resolve_archive_name').and_return( flexmock(module.borgmatic.borg.rlist).should_receive('resolve_archive_name').and_return(
flexmock() flexmock()
) )
flexmock(module.borgmatic.actions.arguments).should_receive('update_arguments').and_return(
flexmock()
)
flexmock(module.borgmatic.borg.list).should_receive('list_archive') flexmock(module.borgmatic.borg.list).should_receive('list_archive')
list_arguments = flexmock(repository=flexmock(), archive=flexmock(), json=flexmock()) list_arguments = flexmock(repository=flexmock(), archive=flexmock(), json=flexmock())