Browse Source

Merge pull request #378 from ThomasWaldmann/list-with-prefix

borg list --prefix=thishostname- REPO, fixes #205
TW 9 years ago
parent
commit
ea10551be2
2 changed files with 15 additions and 0 deletions
  1. 5 0
      borg/archiver.py
  2. 10 0
      borg/testsuite/archiver.py

+ 5 - 0
borg/archiver.py

@@ -414,6 +414,8 @@ class Archiver:
                         remove_surrogates(item[b'path']), extra))
         else:
             for archive_info in manifest.list_archive_infos(sort_by='ts'):
+                if args.prefix and not archive_info.name.startswith(args.prefix):
+                    continue
                 print(format_archive(archive_info))
         return self.exit_code
 
@@ -835,9 +837,12 @@ class Archiver:
         subparser.add_argument('--short', dest='short',
                                action='store_true', default=False,
                                help='only print file/directory names, nothing else')
+        subparser.add_argument('-p', '--prefix', dest='prefix', type=str,
+                               help='only consider archive names starting with this prefix')
         subparser.add_argument('src', metavar='REPOSITORY_OR_ARCHIVE', nargs='?', default='',
                                type=location_validator(),
                                help='repository/archive to list contents of')
+
         mount_epilog = textwrap.dedent("""
         This command mounts an archive as a FUSE filesystem. This can be useful for
         browsing an archive or restoring individual files. Unless the ``--foreground``

+ 10 - 0
borg/testsuite/archiver.py

@@ -675,6 +675,16 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         self.assert_in('bar-2015-08-12-10:00', output)
         self.assert_in('bar-2015-08-12-20:00', output)
 
+    def test_list_prefix(self):
+        self.cmd('init', self.repository_location)
+        self.cmd('create', self.repository_location + '::test-1', src_dir)
+        self.cmd('create', self.repository_location + '::something-else-than-test-1', src_dir)
+        self.cmd('create', self.repository_location + '::test-2', src_dir)
+        output = self.cmd('list', '--prefix=test-', self.repository_location)
+        self.assert_in('test-1', output)
+        self.assert_in('test-2', output)
+        self.assert_not_in('something-else', output)
+
     def test_usage(self):
         if self.FORK_DEFAULT:
             self.cmd(exit_code=0)