From 574eb919213fbde542a5de47c5aa6c4fddebf690 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 7 Mar 2022 21:46:12 -0800 Subject: [PATCH] Fix Borg usage error in the "compact" action when running "borgmatic --dry-run". Now, skip "compact" entirely during a dry run (#507). --- NEWS | 6 ++++-- borgmatic/borg/compact.py | 4 ++-- tests/unit/borg/test_compact.py | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index 6b471c5..611d525 100644 --- a/NEWS +++ b/NEWS @@ -1,7 +1,9 @@ 1.5.24.dev0 - * Add "working_directory" option to support source directories with relative paths (#431). + * #431: Add "working_directory" option to support source directories with relative paths. * #486: Fix handling of "patterns_from" and "exclude_from" options to error instead of warning when - referencing unreadable files and running "create" action. + referencing unreadable files and "create" action is run. + * #507: Fix Borg usage error in the "compact" action when running "borgmatic --dry-run". Now, skip + "compact" entirely during a dry run. 1.5.23 * #394: Compact repository segments and free space with new "borgmatic compact" action. Borg 1.2+ diff --git a/borgmatic/borg/compact.py b/borgmatic/borg/compact.py index 2df6774..42871d3 100644 --- a/borgmatic/borg/compact.py +++ b/borgmatic/borg/compact.py @@ -33,9 +33,9 @@ def compact_segments( + (('--threshold', str(threshold)) if threshold else ()) + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ()) + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ()) - + (('--dry-run',) if dry_run else ()) + (tuple(extra_borg_options.split(' ')) if extra_borg_options else ()) + (repository,) ) - execute_command(full_command, output_log_level=logging.INFO, borg_local_path=local_path) + if not dry_run: + execute_command(full_command, output_log_level=logging.INFO, borg_local_path=local_path) diff --git a/tests/unit/borg/test_compact.py b/tests/unit/borg/test_compact.py index ea13d9a..4ab0cfc 100644 --- a/tests/unit/borg/test_compact.py +++ b/tests/unit/borg/test_compact.py @@ -36,8 +36,8 @@ def test_compact_segments_with_log_debug_calls_borg_with_debug_parameter(): module.compact_segments(repository='repo', storage_config={}, dry_run=False) -def test_compact_segments_with_dry_run_calls_borg_with_dry_run_parameter(): - insert_execute_command_mock(COMPACT_COMMAND + ('--dry-run', 'repo'), logging.INFO) +def test_compact_segments_with_dry_run_skips_borg_call(): + flexmock(module).should_receive('execute_command').never() module.compact_segments(repository='repo', storage_config={}, dry_run=True)