From f9d7faf88418ed4a1aaafec9bcd21597c722a823 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Thu, 18 Aug 2022 23:33:05 -0700 Subject: [PATCH] Fix mount action to work without archive again (#557). --- borgmatic/borg/mount.py | 6 ++++- borgmatic/commands/arguments.py | 5 ++-- tests/unit/borg/test_mount.py | 41 +++++++++++++++++++++++---------- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/borgmatic/borg/mount.py b/borgmatic/borg/mount.py index 370ca13c..c1ad1c3d 100644 --- a/borgmatic/borg/mount.py +++ b/borgmatic/borg/mount.py @@ -42,7 +42,11 @@ def mount_archive( + ('--glob-archives', archive) ) if feature.available(feature.Feature.SEPARATE_REPOSITORY_ARCHIVE, local_borg_version) - else flags.make_repository_archive_flags(repository, archive, local_borg_version) + else ( + flags.make_repository_archive_flags(repository, archive, local_borg_version) + if archive + else flags.make_repository_flags(repository, local_borg_version) + ) ) + (mount_point,) + (tuple(paths) if paths else ()) diff --git a/borgmatic/commands/arguments.py b/borgmatic/commands/arguments.py index bb3ed4b7..e5be542b 100644 --- a/borgmatic/commands/arguments.py +++ b/borgmatic/commands/arguments.py @@ -269,8 +269,8 @@ def make_parsers(): transfer_parser = subparsers.add_parser( 'transfer', aliases=SUBPARSER_ALIASES['transfer'], - help='Transfer archives from one repository to another, optionally upgrading the transferred data', - description='Transfer archives from one repository to another, optionally upgrading the transferred data', + help='Transfer archives from one repository to another, optionally upgrading the transferred data (Borg 2.0+ only)', + description='Transfer archives from one repository to another, optionally upgrading the transferred data (Borg 2.0+ only)', add_help=False, ) transfer_group = transfer_parser.add_argument_group('transfer arguments') @@ -290,7 +290,6 @@ def make_parsers(): transfer_group.add_argument( '--upgrader', help='Upgrader type used to convert the transfered data, e.g. "From12To20" to upgrade data from Borg 1.2 to 2.0 format, defaults to no conversion', - required=True, ) transfer_group.add_argument( '-a', diff --git a/tests/unit/borg/test_mount.py b/tests/unit/borg/test_mount.py index d87a18c8..98bbe1a6 100644 --- a/tests/unit/borg/test_mount.py +++ b/tests/unit/borg/test_mount.py @@ -14,16 +14,14 @@ def insert_execute_command_mock(command): ).once() -def test_mount_archive_calls_borg_with_required_parameters(): +def test_mount_archive_calls_borg_with_required_flags(): flexmock(module.feature).should_receive('available').and_return(False) - flexmock(module.flags).should_receive('make_repository_archive_flags').and_return( - ('repo::archive',) - ) - insert_execute_command_mock(('borg', 'mount', 'repo::archive', '/mnt')) + flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',)) + insert_execute_command_mock(('borg', 'mount', 'repo', '/mnt')) module.mount_archive( repository='repo', - archive='archive', + archive=None, mount_point='/mnt', paths=None, foreground=False, @@ -52,7 +50,26 @@ def test_mount_archive_with_borg_features_calls_borg_with_repository_and_glob_ar ) -def test_mount_archive_calls_borg_with_path_parameters(): +def test_mount_archive_without_archive_calls_borg_with_repository_flags_only(): + flexmock(module.feature).should_receive('available').and_return(False) + flexmock(module.flags).should_receive('make_repository_archive_flags').and_return( + ('repo::archive',) + ) + insert_execute_command_mock(('borg', 'mount', 'repo::archive', '/mnt')) + + module.mount_archive( + repository='repo', + archive='archive', + mount_point='/mnt', + paths=None, + foreground=False, + options=None, + storage_config={}, + local_borg_version='1.2.3', + ) + + +def test_mount_archive_calls_borg_with_path_flags(): flexmock(module.feature).should_receive('available').and_return(False) flexmock(module.flags).should_receive('make_repository_archive_flags').and_return( ('repo::archive',) @@ -71,7 +88,7 @@ def test_mount_archive_calls_borg_with_path_parameters(): ) -def test_mount_archive_calls_borg_with_remote_path_parameters(): +def test_mount_archive_calls_borg_with_remote_path_flags(): flexmock(module.feature).should_receive('available').and_return(False) flexmock(module.flags).should_receive('make_repository_archive_flags').and_return( ('repo::archive',) @@ -93,7 +110,7 @@ def test_mount_archive_calls_borg_with_remote_path_parameters(): ) -def test_mount_archive_calls_borg_with_umask_parameters(): +def test_mount_archive_calls_borg_with_umask_flags(): flexmock(module.feature).should_receive('available').and_return(False) flexmock(module.flags).should_receive('make_repository_archive_flags').and_return( ('repo::archive',) @@ -112,7 +129,7 @@ def test_mount_archive_calls_borg_with_umask_parameters(): ) -def test_mount_archive_calls_borg_with_lock_wait_parameters(): +def test_mount_archive_calls_borg_with_lock_wait_flags(): flexmock(module.feature).should_receive('available').and_return(False) flexmock(module.flags).should_receive('make_repository_archive_flags').and_return( ('repo::archive',) @@ -151,7 +168,7 @@ def test_mount_archive_with_log_info_calls_borg_with_info_parameter(): ) -def test_mount_archive_with_log_debug_calls_borg_with_debug_parameters(): +def test_mount_archive_with_log_debug_calls_borg_with_debug_flags(): flexmock(module.feature).should_receive('available').and_return(False) flexmock(module.flags).should_receive('make_repository_archive_flags').and_return( ('repo::archive',) @@ -196,7 +213,7 @@ def test_mount_archive_calls_borg_with_foreground_parameter(): ) -def test_mount_archive_calls_borg_with_options_parameters(): +def test_mount_archive_calls_borg_with_options_flags(): flexmock(module.feature).should_receive('available').and_return(False) flexmock(module.flags).should_receive('make_repository_archive_flags').and_return( ('repo::archive',)