diff --git a/src/borg/archiver.py b/src/borg/archiver.py index 6efd81ebd..b36dc28f2 100644 --- a/src/borg/archiver.py +++ b/src/borg/archiver.py @@ -913,11 +913,24 @@ class Archiver: @with_repository(cache=True) 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)): + return self._info_archives(args, repository, manifest, key, cache) + else: + return self._info_repository(cache) + + def _info_archives(self, args, repository, manifest, key, cache): def format_cmdline(cmdline): return remove_surrogates(' '.join(shlex.quote(x) for x in cmdline)) if args.location.archive: - archive = Archive(repository, key, manifest, args.location.archive, cache=cache, + archive_names = (args.location.archive,) + else: + archive_names = tuple(x.name for x in self._get_filtered_archives(args, manifest)) + if not archive_names: + return self.exit_code + + for i, archive_name in enumerate(archive_names, 1): + archive = Archive(repository, key, manifest, archive_name, cache=cache, consider_part_files=args.consider_part_files) stats = archive.calc_stats(cache) print('Archive name: %s' % archive.name) @@ -934,9 +947,15 @@ class Archiver: print(STATS_HEADER) print(str(stats)) print(str(cache)) - else: - print(STATS_HEADER) - print(str(cache)) + if self.exit_code: + break + if len(archive_names) - i: + print() + return self.exit_code + + def _info_repository(self, cache): + print(STATS_HEADER) + print(str(cache)) return self.exit_code @with_repository(exclusive=True) @@ -2102,6 +2121,7 @@ class Archiver: subparser.add_argument('location', metavar='REPOSITORY_OR_ARCHIVE', type=location_validator(), help='archive or repository to display information about') + self.add_archives_filters_args(subparser) break_lock_epilog = textwrap.dedent(""" This command breaks the repository and cache locks. diff --git a/src/borg/testsuite/archiver.py b/src/borg/testsuite/archiver.py index 92abd018c..68e9e7b72 100644 --- a/src/borg/testsuite/archiver.py +++ b/src/borg/testsuite/archiver.py @@ -964,6 +964,8 @@ class ArchiverTestCase(ArchiverTestCaseBase): assert 'All archives:' in info_repo info_archive = self.cmd('info', self.repository_location + '::test') assert 'Archive name: test\n' in info_archive + info_archive = self.cmd('info', '--first', '1', self.repository_location) + assert 'Archive name: test\n' in info_archive def test_comment(self): self.create_regular_file('file1', size=1024 * 80)