mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-27 02:08:54 +00:00
--prefix / -P: fix processing, avoid argparse issue, fixes #4769
changes: - changed --prefix default to None (was: ''), so we can check using "is not None" to determine when --prefix has been given. - the previous check for --prefix being used was just for a truthy value, so using --prefix='' was not really supported, but happened to behave the same as the default processing anyway. - argparse python stdlib code seems to have a bug when processing an option like --prefix='--', args.prefix will be [] in that case (should be '--'). With previous code this behaved like no prefix given ([] value is not truthy). Now, as we check for "is not None", it will try to process that value but blow up with a TypeError as it can't do [] + '*'. This is a bit unpretty end, but at least borg prune won't delete all your archives and it will be a reminder that argparse is broken. - for borg check --repository-only, we also check for --glob-archives not being used and give the warning otherwise.
This commit is contained in:
parent
73ab1f1da6
commit
6395126d34
2 changed files with 8 additions and 7 deletions
|
@ -302,7 +302,8 @@ def do_check(self, args, repository):
|
|||
truish=('YES', ), retry=False,
|
||||
env_var_override='BORG_CHECK_I_KNOW_WHAT_I_AM_DOING'):
|
||||
return EXIT_ERROR
|
||||
if args.repo_only and any((args.verify_data, args.first, args.last, args.prefix)):
|
||||
if args.repo_only and any(
|
||||
(args.verify_data, args.first, args.last, args.prefix is not None, args.glob_archives)):
|
||||
self.print_error("--repository-only contradicts --first, --last, --prefix and --verify-data arguments.")
|
||||
return EXIT_ERROR
|
||||
if args.repair and args.max_duration:
|
||||
|
@ -318,7 +319,7 @@ def do_check(self, args, repository):
|
|||
if not args.archives_only:
|
||||
if not repository.check(repair=args.repair, save_space=args.save_space, max_duration=args.max_duration):
|
||||
return EXIT_WARNING
|
||||
if args.prefix:
|
||||
if args.prefix is not None:
|
||||
args.glob_archives = args.prefix + '*'
|
||||
if not args.repo_only and not ArchiveChecker().check(
|
||||
repository, repair=args.repair, archive=args.location.archive,
|
||||
|
@ -1092,7 +1093,7 @@ def do_rename(self, args, repository, manifest, key, cache, archive):
|
|||
@with_repository(exclusive=True, manifest=False)
|
||||
def do_delete(self, args, repository):
|
||||
"""Delete an existing repository or archives"""
|
||||
archive_filter_specified = args.first or args.last or args.prefix or args.glob_archives
|
||||
archive_filter_specified = any((args.first, args.last, args.prefix is not None, args.glob_archives))
|
||||
explicit_archives_specified = args.location.archive or args.archives
|
||||
if archive_filter_specified and explicit_archives_specified:
|
||||
self.print_error('Mixing archive filters and explicitly named archives is not supported.')
|
||||
|
@ -1301,7 +1302,7 @@ def _list_repository(self, args, repository, manifest, key):
|
|||
@with_repository(cache=True, compatibility=(Manifest.Operation.READ,))
|
||||
def do_info(self, args, repository, manifest, key, cache):
|
||||
"""Show archive details such as disk space used"""
|
||||
if any((args.location.archive, args.first, args.last, args.prefix, args.glob_archives)):
|
||||
if any((args.location.archive, args.first, args.last, args.prefix is not None, args.glob_archives)):
|
||||
return self._info_archives(args, repository, manifest, key, cache)
|
||||
else:
|
||||
return self._info_repository(args, repository, manifest, key, cache)
|
||||
|
@ -1397,7 +1398,7 @@ def do_prune(self, args, repository, manifest, key):
|
|||
'"keep-secondly", "keep-minutely", "keep-hourly", "keep-daily", '
|
||||
'"keep-weekly", "keep-monthly" or "keep-yearly" settings must be specified.')
|
||||
return self.exit_code
|
||||
if args.prefix:
|
||||
if args.prefix is not None:
|
||||
args.glob_archives = args.prefix + '*'
|
||||
checkpoint_re = r'\.checkpoint(\.\d+)?'
|
||||
archives_checkpoints = manifest.archives.list(glob=args.glob_archives,
|
||||
|
@ -2582,7 +2583,7 @@ def define_archive_filters_group(subparser, *, sort_by=True, first_last=True):
|
|||
filters_group = subparser.add_argument_group('Archive filters',
|
||||
'Archive filters can be applied to repository targets.')
|
||||
group = filters_group.add_mutually_exclusive_group()
|
||||
group.add_argument('-P', '--prefix', metavar='PREFIX', dest='prefix', type=PrefixSpec, default='',
|
||||
group.add_argument('-P', '--prefix', metavar='PREFIX', dest='prefix', type=PrefixSpec, default=None,
|
||||
help='only consider archive names starting with this prefix.')
|
||||
group.add_argument('-a', '--glob-archives', metavar='GLOB', dest='glob_archives',
|
||||
type=GlobSpec, default=None,
|
||||
|
|
|
@ -103,7 +103,7 @@ def list_considering(self, args):
|
|||
"""
|
||||
if args.location.archive:
|
||||
raise Error('The options --first, --last, --prefix and --glob-archives can only be used on repository targets.')
|
||||
if args.prefix:
|
||||
if args.prefix is not None:
|
||||
args.glob_archives = args.prefix + '*'
|
||||
return self.list(sort_by=args.sort_by.split(','), glob=args.glob_archives, first=args.first, last=args.last)
|
||||
|
||||
|
|
Loading…
Reference in a new issue