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.
* #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.
* #706: Fix "--archive latest" on "list" and "info" actions only working on the first of multiple
configured repositories.
1.7.13
* #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 logging
import borgmatic.actions.arguments
import borgmatic.borg.info
import borgmatic.borg.rlist
import borgmatic.config.validate
@ -29,7 +30,7 @@ def run_info(
logger.answer(
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'],
info_arguments.archive,
storage,
@ -42,7 +43,7 @@ def run_info(
repository['path'],
storage,
local_borg_version,
info_arguments,
borgmatic.actions.arguments.update_arguments(info_arguments, archive=archive_name),
global_arguments,
local_path,
remote_path,

View File

@ -1,6 +1,7 @@
import json
import logging
import borgmatic.actions.arguments
import borgmatic.borg.list
import borgmatic.config.validate
@ -29,7 +30,8 @@ def run_list(
logger.answer(f'{repository.get("label", repository["path"])}: Searching archives')
elif not list_arguments.archive:
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'],
list_arguments.archive,
storage,
@ -42,7 +44,7 @@ def run_list(
repository['path'],
storage,
local_borg_version,
list_arguments,
borgmatic.actions.arguments.update_arguments(list_arguments, archive=archive_name),
global_arguments,
local_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()
)
flexmock(module.borgmatic.actions.arguments).should_receive('update_arguments').and_return(
flexmock()
)
flexmock(module.borgmatic.borg.info).should_receive('display_archives_info')
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()
)
flexmock(module.borgmatic.actions.arguments).should_receive('update_arguments').and_return(
flexmock()
)
flexmock(module.borgmatic.borg.list).should_receive('list_archive')
list_arguments = flexmock(repository=flexmock(), archive=flexmock(), json=flexmock())