From 596dd49cf580185dae534bebb59d71a002308e18 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Wed, 17 Aug 2022 14:26:35 -0700 Subject: [PATCH] Use --glob-archives instead of --prefix on rlist command (#557). --- borgmatic/borg/list.py | 2 +- borgmatic/borg/rlist.py | 9 ++++++-- tests/unit/borg/test_rlist.py | 41 +++++++++++++++++++++++++---------- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/borgmatic/borg/list.py b/borgmatic/borg/list.py index cbca8d7c7..3c2addb24 100644 --- a/borgmatic/borg/list.py +++ b/borgmatic/borg/list.py @@ -41,7 +41,7 @@ def make_list_command( ) + flags.make_flags('remote-path', remote_path) + flags.make_flags('lock-wait', lock_wait) - + flags.make_flags_from_arguments(list_arguments, excludes=MAKE_FLAGS_EXCLUDES,) + + flags.make_flags_from_arguments(list_arguments, excludes=MAKE_FLAGS_EXCLUDES) + ( flags.make_repository_archive_flags( repository, list_arguments.archive, local_borg_version diff --git a/borgmatic/borg/rlist.py b/borgmatic/borg/rlist.py index a4cd1ef3e..c2e9299db 100644 --- a/borgmatic/borg/rlist.py +++ b/borgmatic/borg/rlist.py @@ -51,7 +51,7 @@ def resolve_archive_name( return latest_archive -MAKE_FLAGS_EXCLUDES = ('repository',) +MAKE_FLAGS_EXCLUDES = ('repository', 'prefix') def make_rlist_command( @@ -86,7 +86,12 @@ def make_rlist_command( ) + flags.make_flags('remote-path', remote_path) + flags.make_flags('lock-wait', lock_wait) - + flags.make_flags_from_arguments(rlist_arguments, excludes=MAKE_FLAGS_EXCLUDES,) + + ( + flags.make_flags('glob-archives', f'{rlist_arguments.prefix}*') + if rlist_arguments.prefix + else () + ) + + flags.make_flags_from_arguments(rlist_arguments, excludes=MAKE_FLAGS_EXCLUDES) + flags.make_repository_flags(repository, local_borg_version) ) diff --git a/tests/unit/borg/test_rlist.py b/tests/unit/borg/test_rlist.py index 816843551..d16b53db7 100644 --- a/tests/unit/borg/test_rlist.py +++ b/tests/unit/borg/test_rlist.py @@ -153,7 +153,7 @@ def test_make_rlist_command_includes_log_info(): repository='repo', storage_config={}, local_borg_version='1.2.3', - rlist_arguments=flexmock(archive=None, paths=None, json=False), + rlist_arguments=flexmock(archive=None, paths=None, json=False, prefix=None), ) assert command == ('borg', 'list', '--info', 'repo') @@ -169,7 +169,7 @@ def test_make_rlist_command_includes_json_but_not_info(): repository='repo', storage_config={}, local_borg_version='1.2.3', - rlist_arguments=flexmock(archive=None, paths=None, json=True), + rlist_arguments=flexmock(archive=None, paths=None, json=True, prefix=None), ) assert command == ('borg', 'list', '--json', 'repo') @@ -185,7 +185,7 @@ def test_make_rlist_command_includes_log_debug(): repository='repo', storage_config={}, local_borg_version='1.2.3', - rlist_arguments=flexmock(archive=None, paths=None, json=False), + rlist_arguments=flexmock(archive=None, paths=None, json=False, prefix=None), ) assert command == ('borg', 'list', '--debug', '--show-rc', 'repo') @@ -201,7 +201,7 @@ def test_make_rlist_command_includes_json_but_not_debug(): repository='repo', storage_config={}, local_borg_version='1.2.3', - rlist_arguments=flexmock(archive=None, paths=None, json=True), + rlist_arguments=flexmock(archive=None, paths=None, json=True, prefix=None), ) assert command == ('borg', 'list', '--json', 'repo') @@ -216,7 +216,7 @@ def test_make_rlist_command_includes_json(): repository='repo', storage_config={}, local_borg_version='1.2.3', - rlist_arguments=flexmock(archive=None, paths=None, json=True), + rlist_arguments=flexmock(archive=None, paths=None, json=True, prefix=None), ) assert command == ('borg', 'list', '--json', 'repo') @@ -225,7 +225,7 @@ def test_make_rlist_command_includes_json(): def test_make_rlist_command_includes_lock_wait(): flexmock(module.flags).should_receive('make_flags').and_return(()).and_return( ('--lock-wait', '5') - ) + ).and_return(()) flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(()) flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',)) @@ -233,7 +233,7 @@ def test_make_rlist_command_includes_lock_wait(): repository='repo', storage_config={'lock_wait': 5}, local_borg_version='1.2.3', - rlist_arguments=flexmock(archive=None, paths=None, json=False), + rlist_arguments=flexmock(archive=None, paths=None, json=False, prefix=None), ) assert command == ('borg', 'list', '--lock-wait', '5', 'repo') @@ -248,7 +248,7 @@ def test_make_rlist_command_includes_local_path(): repository='repo', storage_config={}, local_borg_version='1.2.3', - rlist_arguments=flexmock(archive=None, paths=None, json=False), + rlist_arguments=flexmock(archive=None, paths=None, json=False, prefix=None), local_path='borg2', ) @@ -258,7 +258,7 @@ def test_make_rlist_command_includes_local_path(): def test_make_rlist_command_includes_remote_path(): flexmock(module.flags).should_receive('make_flags').and_return( ('--remote-path', 'borg2') - ).and_return(()) + ).and_return(()).and_return(()) flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(()) flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',)) @@ -266,13 +266,30 @@ def test_make_rlist_command_includes_remote_path(): repository='repo', storage_config={}, local_borg_version='1.2.3', - rlist_arguments=flexmock(archive=None, paths=None, json=False), + rlist_arguments=flexmock(archive=None, paths=None, json=False, prefix=None), remote_path='borg2', ) assert command == ('borg', 'list', '--remote-path', 'borg2', 'repo') +def test_make_rlist_command_transforms_prefix_into_glob_archives(): + flexmock(module.flags).should_receive('make_flags').and_return(()).and_return(()).and_return( + ('--glob-archives', 'foo*') + ) + flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(()) + flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',)) + + command = module.make_rlist_command( + repository='repo', + storage_config={}, + local_borg_version='1.2.3', + rlist_arguments=flexmock(archive=None, paths=None, json=False, prefix='foo'), + ) + + assert command == ('borg', 'list', '--glob-archives', 'foo*', 'repo') + + def test_make_rlist_command_includes_short(): flexmock(module.flags).should_receive('make_flags').and_return(()) flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(('--short',)) @@ -282,7 +299,7 @@ def test_make_rlist_command_includes_short(): repository='repo', storage_config={}, local_borg_version='1.2.3', - rlist_arguments=flexmock(archive=None, paths=None, json=False, short=True), + rlist_arguments=flexmock(archive=None, paths=None, json=False, prefix=None, short=True), ) assert command == ('borg', 'list', '--short', 'repo') @@ -291,7 +308,6 @@ def test_make_rlist_command_includes_short(): @pytest.mark.parametrize( 'argument_name', ( - 'prefix', 'glob_archives', 'sort_by', 'first', @@ -317,6 +333,7 @@ def test_make_rlist_command_includes_additional_flags(argument_name): archive=None, paths=None, json=False, + prefix=None, find_paths=None, format=None, **{argument_name: 'value'},