Пример #1
0
    def rsync_gen_delta(file_path_fd, old_file_meta):
        """Get rsync delta for file descriptor provided as arg.

        :param file_path_fd:
        :param old_file_meta:
        :return:
        """

        if not old_file_meta:
            raise StopIteration

        # If the ctime or mtime has changed, the delta is computed
        # data block is returned

        len_deltas = 0
        old_signature = old_file_meta['signature']
        # Get changed blocks index only
        all_changed_indexes = cStringIO()
        file_path_fd.seek(0)
        previous_index = -1
        modified_blocks = []
        for block_index in pyrsync.rsyncdelta(
                file_path_fd,
                (old_signature[0], old_signature[1]),
                RSYNC_BLOCK_SIZE):

            previous_index += 1

            if not isinstance(block_index, int):
                len_deltas += len(block_index)
                all_changed_indexes.write(b'\00{}'.format(previous_index))
                modified_blocks.append(previous_index)

        # Yield the total length data changed blocks

        yield b'\00' + str(len_deltas)
        previous_index_str = all_changed_indexes.getvalue() + b'\00'
        len_previous_index_str = len(previous_index_str) + 1
        # Yield the length of the string that contain all the indexes

        yield b'\00' + str(len_previous_index_str) + b'\00'
        # Yield string containing all the indexes separated by \00

        yield previous_index_str

        # Get blocks of changed data
        file_path_fd.seek(0)
        for block_index in modified_blocks:
            offset = block_index * RSYNC_BLOCK_SIZE
            file_path_fd.seek(offset)
            data_block = file_path_fd.read(RSYNC_BLOCK_SIZE)

            yield data_block
Пример #2
0
    def rsync_gen_delta(file_path_fd, old_file_meta):
        """Get rsync delta for file descriptor provided as arg.

        :param file_path_fd:
        :param old_file_meta:
        :return:
        """

        if not old_file_meta:
            return

        # If the ctime or mtime has changed, the delta is computed
        # data block is returned

        len_deltas = 0
        old_signature = old_file_meta['signature']
        # Get changed blocks index only
        all_changed_indexes = cStringIO()
        file_path_fd.seek(0)
        previous_index = -1
        modified_blocks = []
        for block_index in pyrsync.rsyncdelta(
                file_path_fd,
                (old_signature[0], old_signature[1]),
                RSYNC_BLOCK_SIZE):

            previous_index += 1

            if not isinstance(block_index, int):
                len_deltas += len(block_index)
                all_changed_indexes.write(b'\00{}'.format(previous_index))
                modified_blocks.append(previous_index)

        # Yield the total length data changed blocks

        yield b'\00' + str(len_deltas)
        previous_index_str = all_changed_indexes.getvalue() + b'\00'
        len_previous_index_str = len(previous_index_str) + 1
        # Yield the length of the string that contain all the indexes

        yield b'\00' + str(len_previous_index_str) + b'\00'
        # Yield string containing all the indexes separated by \00

        yield previous_index_str

        # Get blocks of changed data
        file_path_fd.seek(0)
        for block_index in modified_blocks:
            offset = block_index * RSYNC_BLOCK_SIZE
            file_path_fd.seek(offset)
            data_block = file_path_fd.read(RSYNC_BLOCK_SIZE)

            yield data_block
Пример #3
0
    def test_rsyncdelta(self):
        datastream = six.BytesIO(b'addc830058f917ae'
                                 b'a1be5ab4d899b570'
                                 b'85c9534c64d8d71c'
                                 b'1f32cde9c71e5b6d')

        old_weak = [675087508, 698025105, 579470394, 667092162]
        old_strong = ['e72251cb70a1b918ee43876896ebb4c8a7225f78',
                      '3bf6d2483425e8925df06c01ee490e386a9a707a',
                      '0ba97d95cc49b1ee2863b7dec3d49911502111c2',
                      '8b92d9f3f6679e1c8ce2f20e2a6217fd7f351f8f']

        changed_indexes = []
        cur_index = 0
        for block_index in pyrsync.rsyncdelta(datastream,
                                              (old_weak, old_strong), 16):
            if not isinstance(block_index, int):
                changed_indexes.append(cur_index)
            cur_index += 1
        exp_changed_indexes = [0, 2]
        self.assertEqual(changed_indexes[:-1], exp_changed_indexes)
Пример #4
0
    def test_rsyncdelta(self):
        datastream = io.BytesIO(b'addc830058f917ae'
                                b'a1be5ab4d899b570'
                                b'85c9534c64d8d71c'
                                b'1f32cde9c71e5b6d')

        old_weak = [675087508, 698025105, 579470394, 667092162]
        old_strong = [
            'e72251cb70a1b918ee43876896ebb4c8a7225f78',
            '3bf6d2483425e8925df06c01ee490e386a9a707a',
            '0ba97d95cc49b1ee2863b7dec3d49911502111c2',
            '8b92d9f3f6679e1c8ce2f20e2a6217fd7f351f8f'
        ]

        changed_indexes = []
        cur_index = 0
        for block_index in pyrsync.rsyncdelta(datastream,
                                              (old_weak, old_strong), 16):
            if not isinstance(block_index, int):
                changed_indexes.append(cur_index)
            cur_index += 1
        exp_changed_indexes = [0, 2]
        self.assertEqual(changed_indexes[:-1], exp_changed_indexes)