add --dry-run feature check

This commit is contained in:
Vandal
2025-04-23 08:11:43 +05:30
parent dbf1d0946a
commit 27a2bbc231
3 changed files with 26 additions and 2 deletions
+7 -2
View File
@@ -1,7 +1,7 @@
import logging
import borgmatic.config.paths
from borgmatic.borg import environment, flags
from borgmatic.borg import environment, feature, flags
from borgmatic.execute import execute_command
logger = logging.getLogger(__name__)
@@ -42,7 +42,12 @@ def compact_segments(
)
if dry_run:
logging.info('Skipping compact (dry run)')
if feature.available(feature.Feature.DRY_RUN_COMPACT, local_borg_version):
logging.info('Skipping compact (dry run)')
else:
logging.warning(
'The --dry-run option is not supported for compact in the current version of Borg.'
)
return
execute_command(
+2
View File
@@ -18,6 +18,7 @@ class Feature(Enum):
EXCLUDED_FILES_MINUS = 12
ARCHIVE_SERIES = 13
NO_PRUNE_STATS = 14
DRY_RUN_COMPACT = 15
FEATURE_TO_MINIMUM_BORG_VERSION = {
@@ -35,6 +36,7 @@ FEATURE_TO_MINIMUM_BORG_VERSION = {
Feature.EXCLUDED_FILES_MINUS: parse('2.0.0b5'), # --list --filter uses "-" for excludes
Feature.ARCHIVE_SERIES: parse('2.0.0b11'), # identically named archives form a series
Feature.NO_PRUNE_STATS: parse('2.0.0b10'), # prune --stats is not available
Feature.DRY_RUN_COMPACT: parse('1.4.1'), # borg compact --dry-run support
}
+17
View File
@@ -69,8 +69,25 @@ def test_compact_segments_with_log_debug_calls_borg_with_debug_flag():
def test_compact_segments_with_dry_run_skips_borg_call():
# Test borg version supports dry run.
logger_mock = flexmock(logging)
logger_mock.should_receive('info').with_args('Skipping compact (dry run)').once()
flexmock(module).should_receive('execute_command').never()
module.compact_segments(
repository_path='repo',
config={},
local_borg_version='1.4.1',
global_arguments=flexmock(),
dry_run=True,
)
# Test borg version that does not support dry run.
logger_mock.should_receive('warning').with_args(
'The --dry-run option is not supported for compact in the current version of Borg.'
).once()
module.compact_segments(
repository_path='repo',
config={},