浏览代码

fix dry run not working borg 1.4.1+

Vandal 1 月之前
父节点
当前提交
1cde65b4eb
共有 2 个文件被更改,包括 7 次插入0 次删除
  1. 5 0
      borgmatic/borg/compact.py
  2. 2 0
      tests/unit/borg/test_compact.py

+ 5 - 0
borgmatic/borg/compact.py

@@ -37,6 +37,11 @@ def compact_segments(
         + (('--threshold', str(threshold)) if threshold else ())
         + (('--threshold', str(threshold)) if threshold else ())
         + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
         + (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
         + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
         + (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
+        + (
+            ('--dry-run',)
+            if dry_run and feature.available(feature.Feature.DRY_RUN_COMPACT, local_borg_version)
+            else ()
+        )
         + (tuple(extra_borg_options.split(' ')) if extra_borg_options else ())
         + (tuple(extra_borg_options.split(' ')) if extra_borg_options else ())
         + flags.make_repository_flags(repository_path, local_borg_version)
         + flags.make_repository_flags(repository_path, local_borg_version)
     )
     )

+ 2 - 0
tests/unit/borg/test_compact.py

@@ -73,6 +73,8 @@ def test_compact_segments_with_dry_run_skips_borg_call_when_feature_unavailable(
     flexmock(module.feature).should_receive('available').with_args(
     flexmock(module.feature).should_receive('available').with_args(
         module.feature.Feature.DRY_RUN_COMPACT, '1.2.3'
         module.feature.Feature.DRY_RUN_COMPACT, '1.2.3'
     ).and_return(False)
     ).and_return(False)
+    flexmock(module.environment).should_receive('make_environment').never()
+    flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').never()
     flexmock(module).should_receive('execute_command').never()
     flexmock(module).should_receive('execute_command').never()
     flexmock(logging).should_receive('info').with_args('Skipping compact (dry run)').once()
     flexmock(logging).should_receive('info').with_args('Skipping compact (dry run)').once()