diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index db94e2fa..cb61d0ee 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -420,7 +420,7 @@ def create_archive( f'{repository_path}: Ignoring configured "read_special" value of false, as true is needed for database hooks.' ) - create_command = ( + create_flags = ( tuple(local_path.split(' ')) + ('create',) + make_pattern_flags(config, pattern_file.name if pattern_file else None) @@ -449,12 +449,12 @@ def create_archive( ) + (('--dry-run',) if dry_run else ()) + (tuple(extra_borg_options.split(' ')) if extra_borg_options else ()) - + flags.make_repository_archive_flags( - repository_path, archive_name_format, local_borg_version - ) - + (sources if not pattern_file else ()) ) + create_positional_arguments = flags.make_repository_archive_flags( + repository_path, archive_name_format, local_borg_version + ) + (sources if not pattern_file else ()) + if json: output_log_level = None elif list_files or (stats and not dry_run): @@ -473,7 +473,7 @@ def create_archive( if stream_processes and not config.get('read_special'): logger.debug(f'{repository_path}: Collecting special file paths') special_file_paths = collect_special_file_paths( - create_command, + create_flags + create_positional_arguments, local_path, working_directory, borg_environment, @@ -490,9 +490,9 @@ def create_archive( ), pattern_file=exclude_file, ) - create_command += make_exclude_flags(config, exclude_file.name) + create_flags += make_exclude_flags(config, exclude_file.name) - create_command += ( + create_flags += ( (('--info',) if logger.getEffectiveLevel() == logging.INFO and not json else ()) + (('--stats',) if stats and not json and not dry_run else ()) + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) and not json else ()) @@ -502,7 +502,7 @@ def create_archive( if stream_processes: return execute_command_with_processes( - create_command, + create_flags + create_positional_arguments, stream_processes, output_log_level, output_file, @@ -512,14 +512,14 @@ def create_archive( ) elif output_log_level is None: return execute_command_and_capture_output( - create_command, + create_flags + create_positional_arguments, working_directory=working_directory, extra_environment=borg_environment, borg_local_path=local_path, ) else: execute_command( - create_command, + create_flags + create_positional_arguments, output_log_level, output_file, borg_local_path=local_path, diff --git a/tests/unit/borg/test_create.py b/tests/unit/borg/test_create.py index 97208f04..e4f12842 100644 --- a/tests/unit/borg/test_create.py +++ b/tests/unit/borg/test_create.py @@ -760,7 +760,7 @@ def test_create_archive_with_log_info_calls_borg_with_info_parameter(): ) flexmock(module.environment).should_receive('make_environment') flexmock(module).should_receive('execute_command').with_args( - ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--info',), + ('borg', 'create', '--info') + REPO_ARCHIVE_WITH_PATHS, output_log_level=logging.INFO, output_file=None, borg_local_path='borg', @@ -803,7 +803,7 @@ def test_create_archive_with_log_info_and_json_suppresses_most_borg_output(): ) flexmock(module.environment).should_receive('make_environment') flexmock(module).should_receive('execute_command_and_capture_output').with_args( - ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--json',), + ('borg', 'create', '--json') + REPO_ARCHIVE_WITH_PATHS, working_directory=None, extra_environment=None, borg_local_path='borg', @@ -845,7 +845,7 @@ def test_create_archive_with_log_debug_calls_borg_with_debug_parameter(): ) flexmock(module.environment).should_receive('make_environment') flexmock(module).should_receive('execute_command').with_args( - ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--debug', '--show-rc'), + ('borg', 'create', '--debug', '--show-rc') + REPO_ARCHIVE_WITH_PATHS, output_log_level=logging.INFO, output_file=None, borg_local_path='borg', @@ -888,7 +888,7 @@ def test_create_archive_with_log_debug_and_json_suppresses_most_borg_output(): ) flexmock(module.environment).should_receive('make_environment') flexmock(module).should_receive('execute_command_and_capture_output').with_args( - ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--json',), + ('borg', 'create', '--json') + REPO_ARCHIVE_WITH_PATHS, working_directory=None, extra_environment=None, borg_local_path='borg', @@ -974,7 +974,7 @@ def test_create_archive_with_stats_and_dry_run_calls_borg_without_stats_paramete ) flexmock(module.environment).should_receive('make_environment') flexmock(module).should_receive('execute_command').with_args( - ('borg', 'create', '--dry-run') + REPO_ARCHIVE_WITH_PATHS + ('--info',), + ('borg', 'create', '--dry-run', '--info') + REPO_ARCHIVE_WITH_PATHS, output_log_level=logging.INFO, output_file=None, borg_local_path='borg', @@ -1849,7 +1849,7 @@ def test_create_archive_with_stats_calls_borg_with_stats_parameter_and_answer_ou ) flexmock(module.environment).should_receive('make_environment') flexmock(module).should_receive('execute_command').with_args( - ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--stats',), + ('borg', 'create', '--stats') + REPO_ARCHIVE_WITH_PATHS, output_log_level=module.borgmatic.logger.ANSWER, output_file=None, borg_local_path='borg', @@ -1935,12 +1935,7 @@ def test_create_archive_with_progress_and_log_info_calls_borg_with_progress_para ) flexmock(module.environment).should_receive('make_environment') flexmock(module).should_receive('execute_command').with_args( - ('borg', 'create') - + REPO_ARCHIVE_WITH_PATHS - + ( - '--info', - '--progress', - ), + ('borg', 'create', '--info', '--progress') + REPO_ARCHIVE_WITH_PATHS, output_log_level=logging.INFO, output_file=module.DO_NOT_CAPTURE, borg_local_path='borg', @@ -1984,7 +1979,7 @@ def test_create_archive_with_progress_calls_borg_with_progress_parameter(): ) flexmock(module.environment).should_receive('make_environment') flexmock(module).should_receive('execute_command').with_args( - ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--progress',), + ('borg', 'create', '--progress') + REPO_ARCHIVE_WITH_PATHS, output_log_level=logging.INFO, output_file=module.DO_NOT_CAPTURE, borg_local_path='borg', @@ -2029,10 +2024,12 @@ def test_create_archive_with_progress_and_stream_processes_calls_borg_with_progr flexmock(module.environment).should_receive('make_environment') flexmock(module).should_receive('collect_special_file_paths').and_return(()) create_command = ( - ('borg', 'create', '--one-file-system', '--read-special') - + REPO_ARCHIVE_WITH_PATHS - + ('--progress',) - ) + 'borg', + 'create', + '--one-file-system', + '--read-special', + '--progress', + ) + REPO_ARCHIVE_WITH_PATHS flexmock(module).should_receive('execute_command_with_processes').with_args( create_command + ('--dry-run', '--list'), processes=processes, @@ -2158,14 +2155,14 @@ def test_create_archive_with_stream_processes_adds_special_files_to_excludes(): ) flexmock(module.environment).should_receive('make_environment') flexmock(module).should_receive('collect_special_file_paths').and_return(('special',)) - create_command = ( + create_flags = ( 'borg', 'create', '--one-file-system', '--read-special', - ) + REPO_ARCHIVE_WITH_PATHS + ) flexmock(module).should_receive('execute_command_with_processes').with_args( - create_command + ('--dry-run', '--list'), + create_flags + ('--dry-run', '--list') + REPO_ARCHIVE_WITH_PATHS, processes=processes, output_log_level=logging.INFO, output_file=None, @@ -2174,7 +2171,7 @@ def test_create_archive_with_stream_processes_adds_special_files_to_excludes(): extra_environment=None, ) flexmock(module).should_receive('execute_command_with_processes').with_args( - create_command + ('--exclude-from', '/excludes'), + create_flags + ('--exclude-from', '/excludes') + REPO_ARCHIVE_WITH_PATHS, processes=processes, output_log_level=logging.INFO, output_file=None, @@ -2282,7 +2279,7 @@ def test_create_archive_with_json_calls_borg_with_json_parameter(): ) flexmock(module.environment).should_receive('make_environment') flexmock(module).should_receive('execute_command_and_capture_output').with_args( - ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--json',), + ('borg', 'create', '--json') + REPO_ARCHIVE_WITH_PATHS, working_directory=None, extra_environment=None, borg_local_path='borg', @@ -2325,7 +2322,7 @@ def test_create_archive_with_stats_and_json_calls_borg_without_stats_parameter() ) flexmock(module.environment).should_receive('make_environment') flexmock(module).should_receive('execute_command_and_capture_output').with_args( - ('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--json',), + ('borg', 'create', '--json') + REPO_ARCHIVE_WITH_PATHS, working_directory=None, extra_environment=None, borg_local_path='borg',