Ejemplo n.º 1
0
 def _check_result_of_sync(self, stdout):
     self.assertRegex(stdout, r'^Web ui started on port \d{4}$')
     count = 0
     for path in self.fs._paths:
         if len(path) < 3:
             continue
         if (path[:2] == ('backups', 'home') and
                 path[2] not in ('1995', 'tmp')):
             if path == ('backups', 'home', 'db', 'content'):
                 continue
             count += 1
             item1 = self.fs._paths[path]
             item2 = self.fs._paths[('backups', 'second') + path[2:]]
             self.assertEqual(item1.is_directory, item2.is_directory)
             if not item1.is_directory:
                 self.assertEqual(item1.data, item2.data, path[2:])
     self.assertEqual(35, count)
     cids1 = []
     with datafile.open_content(self.fs, ('backups', 'home', 'db')) as cf:
         for item in cf:
             if item.kind == 'content':
                 cids1.append(item.cid)
     cids2 = []
     with datafile.open_content(self.fs, ('backups', 'second', 'db')) as cf:
         for item in cf:
             if item.kind == 'content':
                 self.assertEqual(789266769, item.first)
                 cids2.append(item.cid)
     self.assertCountEqual(cids1, cids2)
Ejemplo n.º 2
0
    def test_create_content_db_then_open_and_write_to_it(self):
        tree = FakeTree()
        tree._add_directory(('path', 'to', 'db'))

        content = datafile.create_content_in_replacement_mode(
            tree, ('path', 'to', 'db'))
        self.assertCountEqual(
            (('path', 'to', 'db', 'content.new'),),
            tree._files_modified)
        content.commit_and_close()
        self.assertCountEqual(
            (('path', 'to', 'db', 'content.new'),
             ('path', 'to', 'db', 'content')),
            tree._files_modified)
        tree._files_modified = []
        content = datafile.open_content(
            tree, ('path', 'to', 'db'), writable=True)
        cid1 = b'010----hhhh'
        content.append_item(datafile.ItemContent(cid1, cid1, 1417658340))
        cid2 = b'0200000000000000000000a'
        cksum2 = b'0200000000000000000000'
        item = datafile.ItemContent(cid2, cksum2, 1405569942)
        content.append_item(item)
        cid3 = b'040xxxxxx'
        item = datafile.ItemContent(cid3, cid3, 1402958556)
        content.append_item(item)
        content.close()
        self.assertCountEqual(
            (('path', 'to', 'db', 'content'),),
            tree._files_modified)
        tree._files_modified = []
        self.assertEqual(
            8192,
            len(tree._files[('path', 'to', 'db', 'content')].content))
        content = datafile.open_content(tree, ('path', 'to', 'db'))
        self.assertEqual('magic', next(content).kind)
        item = next(content)
        while item.kind == 'setting':
            item = next(content)
        self.assertEqual('content', item.kind)
        self.assertEqual(cid1, item.cid)
        self.assertEqual(cid1, item.checksum)
        self.assertEqual(1417658340, item.first)
        item = next(content)
        self.assertEqual('content', item.kind)
        self.assertEqual(cid2, item.cid)
        self.assertEqual(cksum2, item.checksum)
        self.assertEqual(1405569942, item.first)
        item = next(content)
        self.assertEqual('content', item.kind)
        self.assertEqual(cid3, item.cid)
        self.assertEqual(cid3, item.checksum)
        self.assertEqual(1402958556, item.first)
        self.assertRaises(StopIteration, next, content)
        content.close()
        self.assertCountEqual((), tree._files_modified)
Ejemplo n.º 3
0
    def test_read_and_write_content_db(self):
        expect = StandardItemData()
        expect.load_content_1()
        expect.append_item(
            { 'kind':'content',
              'cid':b'this is a new file',
              'checksum':b'this is a new file',
              'first':1409428462 })
        expect.append_item(
            { 'kind':'content',
              'cid':b'this is another one',
              'checksum':b'this is another one',
              'first':1402611839 } )
        tree = FakeTree()
        tree._add_file(
            ('path', 'to', 'db', 'content'),
            testdata.dbfiledata('content-1'))

        content = datafile.open_content(
            tree, ('path', 'to', 'db'), writable=True)
        content.append_item(
            datafile.ItemContent(
                b'this is a new file', b'this is a new file', 1409428462))
        content.append_item(
            datafile.ItemContent(
                b'this is another one', b'this is another one', 1402611839))
        self.assertItemSequence(expect.items, content)
        self.assertRaises(StopIteration, next, content)
        content.close()
        self.assertCountEqual(
            (('path', 'to', 'db', 'content'),), tree._files_modified)
        tree._files_modified = []
        content = datafile.open_content(tree, ('path', 'to', 'db'))
        self.assertItemSequence(expect.items, content)
        self.assertRaises(StopIteration, next, content)
        content.close()
        self.assertCountEqual((), tree._files_modified)
Ejemplo n.º 4
0
    def test_read_typical_content_db(self):
        tree = FakeTree()
        tree._add_file(
            ('path', 'to', 'db', 'content'),
            testdata.dbfiledata('content-1'))
        expect = StandardItemData()
        expect.load_content_1()

        content = datafile.open_content(tree, ('path', 'to', 'db'))
        self.assertItemSequence(expect.items, content)
        self.assertRaises(StopIteration, next, content)
        self.assertRaises(StopIteration, next, content)
        self.assertRaises(StopIteration, next, content)
        content.close()
        self.assertCountEqual((), tree._files_modified)
Ejemplo n.º 5
0
 def _read_file(self, bkpath):
     fs = filesys.get_file_system('local')
     dbpath = fs.path_from_string(os.path.join(bkpath, 'db'))
     with datafile.open_content(fs, dbpath) as df:
         self._read_datafile(df)
Ejemplo n.º 6
0
    def test_create_multi_block_content_db(self):
        tree = FakeTree()
        tree._add_directory(('path', 'to', 'db'))

        content = datafile.create_content_in_replacement_mode(
            tree, ('path', 'to', 'db'))
        # This item is sized so that the first data block is exactly filled.
        content.append_item(
            datafile.ItemContent(b'000000', b'000000', 1403044159))
        cid1 = b'010----x'
        for i in range(500):
            item = datafile.ItemContent(cid1, cid1, 1417658340)
            content.append_item(item)
        self.assertCountEqual(
            (('path', 'to', 'db', 'content.new'),),
            tree._files_modified)
        content.commit_and_close()
        self.assertCountEqual(
            (('path', 'to', 'db', 'content.new'),
             ('path', 'to', 'db', 'content')),
            tree._files_modified)
        tree._files_modified = []
        self.assertEqual(
            4 * 4096,
            len(tree._files[('path', 'to', 'db', 'content')].content))
        content = datafile.open_content(tree, ('path', 'to', 'db'))
        self.assertEqual('magic', next(content).kind)
        item = next(content)
        while item.kind == 'setting':
            item = next(content)
        self.assertEqual('content', item.kind)
        self.assertEqual(b'000000', item.cid)
        self.assertEqual(b'000000', item.checksum)
        self.assertEqual(1403044159, item.first)
        for i in range(500):
            item = next(content)
            self.assertEqual('content', item.kind)
            self.assertEqual(cid1, item.cid)
            self.assertEqual(cid1, item.checksum)
            self.assertEqual(1417658340, item.first)
        self.assertRaises(StopIteration, next, content)
        content.close()
        self.assertCountEqual((), tree._files_modified)
        data = tree._files[('path', 'to', 'db', 'content')].content
        self.assertEqual(
            b'ebakup content data\nedb-blocksize:4096\n', data[:39])
        # Check that the first data block starts with the first item
        # (which is different from the others so it is identifiable).
        self.assertEqual(
            b'\xdd\x06\x06000000\x3f\xc1\xa0\x53\x3f\xc1\xa0\x53',
            data[4096:4113])
        # Check that the first data block is exactly filled.
        self.assertEqual(
            b'\xdd\x08\x08' + cid1 + b'\xe4\xbf\x7f\x54\xe4\xbf\x7f\x54',
            data[4096+4045:4096+4064])
        # Check that the second data block has its last item in the
        # expected place...
        self.assertEqual(
            b'\xdd\x08\x08' + cid1 + b'\xe4\xbf\x7f\x54\xe4\xbf\x7f\x54',
            data[8192+4028:8192+4047])
        # ... followed by correct padding
        self.assertEqual(b'\x00' * 17, data[8192+4047:8192+4064])
        # Check that the final item is in the expected place...
        self.assertEqual(
            b'\xdd\x08\x08' + cid1 + b'\xe4\xbf\x7f\x54\xe4\xbf\x7f\x54',
            data[12288 + 73 * 19 : 12288 + 74 * 19])
        # ... followed by correct padding
        self.assertEqual(b'\x00' * 2658, data[12288 + 74 * 19 : 12288 + 4064])