Ver código fonte

Fix Borg usage error in the "compact" action when running "borgmatic --dry-run". Now, skip "compact" entirely during a dry run (#507).

Dan Helfman 3 anos atrás
pai
commit
574eb91921
3 arquivos alterados com 8 adições e 6 exclusões
  1. 4 2
      NEWS
  2. 2 2
      borgmatic/borg/compact.py
  3. 2 2
      tests/unit/borg/test_compact.py

+ 4 - 2
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+

+ 2 - 2
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)

+ 2 - 2
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)