浏览代码

silence file listing unless --changed is present

Antoine Beaupré 9 年之前
父节点
当前提交
9899eaf241
共有 2 个文件被更改,包括 26 次插入1 次删除
  1. 5 1
      borg/archiver.py
  2. 21 0
      borg/testsuite/archiver.py

+ 5 - 1
borg/archiver.py

@@ -74,7 +74,8 @@ class Archiver:
         logger.warning(msg)
 
     def print_file_status(self, status, path):
-        logger.info("1s %s", status, remove_surrogates(path))
+        if self.args.changed:
+            logger.info("%1s %s" % (status, remove_surrogates(path)))
 
     def do_serve(self, args):
         """Start in server mode. This command is usually not used manually.
@@ -801,6 +802,8 @@ class Archiver:
                                help="""toggle progress display while creating the archive, showing Original,
                                Compressed and Deduplicated sizes, followed by the Number of files seen
                                and the path being processed, default: %(default)s""")
+        subparser.add_argument('--changed', action='store_true', dest='changed', default=False,
+                               help="""display which files were added to the archive""")
         subparser.add_argument('-e', '--exclude', dest='excludes',
                                type=ExcludePattern, action='append',
                                metavar="PATTERN", help='exclude paths matching PATTERN')
@@ -1171,6 +1174,7 @@ class Archiver:
             args = self.preprocess_args(args)
         parser = self.build_parser(args)
         args = parser.parse_args(args or ['-h'])
+        self.args = args
         update_excludes(args)
         return args
 

+ 21 - 0
borg/testsuite/archiver.py

@@ -723,6 +723,27 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         # http://borgbackup.readthedocs.org/en/latest/faq.html#i-am-seeing-a-added-status-for-a-unchanged-file
         self.assert_in("A input/file2", output)
 
+    def test_create_topical(self):
+        self.create_regular_file('file1', size=1024 * 80)
+        self.cmd('init', self.repository_location)
+        # no listing by default
+        output = self.cmd('create', self.repository_location + '::test', 'input')
+        self.assert_not_in('file1', output)
+        # shouldn't be listed even if unchanged
+        output = self.cmd('create', self.repository_location + '::test0', 'input')
+        self.assert_not_in('file1', output)
+        # should list the file as unchanged
+        #output = self.cmd('create', '--unchanged', self.repository_location + '::test1', 'input')
+        #self.assert_in('file1', output)
+        # should *not* list the file as changed
+        #output = self.cmd('create', '--changed', self.repository_location + '::test2', 'input')
+        #self.assert_not_in('file1', output)
+        # change the file
+        self.create_regular_file('file1', size=1024 * 100)
+        # should list the file as changed
+        output = self.cmd('create', '--changed', self.repository_location + '::test3', 'input')
+        self.assert_in('file1', output)
+
     def test_cmdline_compatibility(self):
         self.create_regular_file('file1', size=1024 * 80)
         self.cmd('init', self.repository_location)