From 6fb7ac44b686a689719d835f3a0685a672a1aedc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Borgstr=C3=B6m?= Date: Sat, 22 Jun 2013 13:33:21 +0200 Subject: [PATCH] Fix include/exclude filter issue --- darc/archive.py | 8 ++++---- darc/test.py | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/darc/archive.py b/darc/archive.py index ac3d3bbb5..4be6eccfb 100644 --- a/darc/archive.py +++ b/darc/archive.py @@ -49,10 +49,11 @@ class ItemIter(object): return item def get_next(self): - n = next(self.unpacker) - while self.filter and not self.filter(n): + while True: n = next(self.unpacker) - return n + decode_dict(n, (b'path', b'source', b'user', b'group')) + if not self.filter or self.filter(n): + return n def peek(self): while True: @@ -143,7 +144,6 @@ class Archive(object): unpacker.feed(self.key.decrypt(id, chunk)) iter = ItemIter(unpacker, filter) for item in iter: - decode_dict(item, (b'path', b'source', b'user', b'group')) yield item, iter.peek def add_item(self, item): diff --git a/darc/test.py b/darc/test.py index c842a9320..9ef1f615f 100644 --- a/darc/test.py +++ b/darc/test.py @@ -137,6 +137,18 @@ class Test(unittest.TestCase): # end the same way as info_output assert info_output2.endswith(info_output) + def test_extract_include_exclude(self): + self.darc('init', self.repository_location) + self.create_regual_file('file1', size=1024 * 80) + self.create_regual_file('file2', size=1024 * 80) + self.create_regual_file('file3', size=1024 * 80) + self.create_regual_file('file4', size=1024 * 80) + self.darc('create', '--exclude=input/file4', self.repository_location + '::test', 'input') + self.darc('extract', '--include=file1', self.repository_location + '::test', 'output') + self.assertEqual(sorted(os.listdir('output/input')), ['file1']) + self.darc('extract', '--exclude=file2', self.repository_location + '::test', 'output') + self.assertEqual(sorted(os.listdir('output/input')), ['file1', 'file3']) + def test_overwrite(self): self.create_regual_file('file1', size=1024 * 80) self.create_regual_file('dir2/file2', size=1024 * 80) @@ -222,10 +234,11 @@ def suite(): suite = unittest.TestSuite() suite.addTest(unittest.TestLoader().loadTestsFromTestCase(ChunkTest)) suite.addTest(unittest.TestLoader().loadTestsFromTestCase(Test)) - suite.addTest(unittest.TestLoader().loadTestsFromTestCase(RemoteTest)) + if not '--no-remote' in sys.argv: + suite.addTest(unittest.TestLoader().loadTestsFromTestCase(RemoteTest)) + suite.addTest(RemoteRepositorySuite()) suite.addTest(KeySuite()) suite.addTest(RepositorySuite()) - suite.addTest(RemoteRepositorySuite()) suite.addTest(doctest.DocTestSuite(helpers)) suite.addTest(lrucache.suite()) suite.addTest(crypto.suite())