Fix error when running the "prune" action with both "archive_name_format" and "prefix" options set (#668).
This commit is contained in:
parent
080c3afa0d
commit
192bfe46a9
3 changed files with 34 additions and 12 deletions
2
NEWS
2
NEWS
|
@ -2,6 +2,8 @@
|
||||||
* #666: Fix error when running the "info" action with the "--match-archives" flag. Also fix the
|
* #666: Fix error when running the "info" action with the "--match-archives" flag. Also fix the
|
||||||
"--match-archives" flag to correctly override the "match_archives" configuration option for
|
"--match-archives" flag to correctly override the "match_archives" configuration option for
|
||||||
the "transfer", "list", "rlist", and "info" actions.
|
the "transfer", "list", "rlist", and "info" actions.
|
||||||
|
* #668: Fix error when running the "prune" action with both "archive_name_format" and "prefix"
|
||||||
|
options set.
|
||||||
|
|
||||||
1.7.11
|
1.7.11
|
||||||
* #479, #588: BREAKING: Automatically use the "archive_name_format" option to filter which archives
|
* #479, #588: BREAKING: Automatically use the "archive_name_format" option to filter which archives
|
||||||
|
|
|
@ -26,22 +26,24 @@ def make_prune_flags(storage_config, retention_config, local_borg_version):
|
||||||
config = retention_config.copy()
|
config = retention_config.copy()
|
||||||
prefix = config.pop('prefix', None)
|
prefix = config.pop('prefix', None)
|
||||||
|
|
||||||
if prefix:
|
|
||||||
if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version):
|
|
||||||
config['match_archives'] = f'sh:{prefix}*'
|
|
||||||
else:
|
|
||||||
config['glob_archives'] = f'{prefix}*'
|
|
||||||
|
|
||||||
flag_pairs = (
|
flag_pairs = (
|
||||||
('--' + option_name.replace('_', '-'), str(value)) for option_name, value in config.items()
|
('--' + option_name.replace('_', '-'), str(value)) for option_name, value in config.items()
|
||||||
)
|
)
|
||||||
|
|
||||||
return tuple(
|
return tuple(element for pair in flag_pairs for element in pair) + (
|
||||||
element for pair in flag_pairs for element in pair
|
(
|
||||||
) + flags.make_match_archives_flags(
|
('--match-archives', f'sh:{prefix}*')
|
||||||
storage_config.get('match_archives'),
|
if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version)
|
||||||
storage_config.get('archive_name_format'),
|
else ('--glob-archives', f'{prefix}*')
|
||||||
local_borg_version,
|
)
|
||||||
|
if prefix
|
||||||
|
else (
|
||||||
|
flags.make_match_archives_flags(
|
||||||
|
storage_config.get('match_archives'),
|
||||||
|
storage_config.get('archive_name_format'),
|
||||||
|
local_borg_version,
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,24 @@ def test_make_prune_flags_with_prefix_without_borg_features_uses_glob_archives()
|
||||||
assert result == expected
|
assert result == expected
|
||||||
|
|
||||||
|
|
||||||
|
def test_make_prune_flags_prefers_prefix_to_archive_name_format():
|
||||||
|
storage_config = {'archive_name_format': 'bar-{now}'} # noqa: FS003
|
||||||
|
retention_config = OrderedDict((('keep_daily', 1), ('prefix', 'bar-')))
|
||||||
|
flexmock(module.feature).should_receive('available').and_return(True)
|
||||||
|
flexmock(module.flags).should_receive('make_match_archives_flags').never()
|
||||||
|
|
||||||
|
result = module.make_prune_flags(storage_config, retention_config, local_borg_version='1.2.3')
|
||||||
|
|
||||||
|
expected = (
|
||||||
|
'--keep-daily',
|
||||||
|
'1',
|
||||||
|
'--match-archives',
|
||||||
|
'sh:bar-*', # noqa: FS003
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result == expected
|
||||||
|
|
||||||
|
|
||||||
def test_make_prune_flags_without_prefix_uses_archive_name_format_instead():
|
def test_make_prune_flags_without_prefix_uses_archive_name_format_instead():
|
||||||
storage_config = {'archive_name_format': 'bar-{now}'} # noqa: FS003
|
storage_config = {'archive_name_format': 'bar-{now}'} # noqa: FS003
|
||||||
retention_config = OrderedDict((('keep_daily', 1), ('prefix', None)))
|
retention_config = OrderedDict((('keep_daily', 1), ('prefix', None)))
|
||||||
|
|
Loading…
Reference in a new issue