'Restore a v1 volume backup.'

def _restore_v1(self, backup, volume_id, metadata, volume_file):

    backup_id = backup['id']
    LOG.debug('v1    volume    backup    restore    of    %s    started.', backup_id)
    extra_metadata = metadata.get('extra_metadata')
    container = backup['container']
    metadata_objects = metadata['objects']
    metadata_object_names = []
    for obj in metadata_objects:
        metadata_object_names.extend(obj.keys())
    LOG.debug('metadata_object_names    =    %s.', metadata_object_names)
    prune_list = [self._metadata_filename(backup), self._sha256_filename(backup)]
    object_names = [object_name for object_name in self._generate_object_names(backup) if (object_name not in prune_list)]
    if (sorted(object_names) != sorted(metadata_object_names)):
        err = _('restore_backup    aborted,    actual    object    list    does    not    match    object    list    stored    in    metadata.')
        raise exception.InvalidBackup(reason=err)
    for metadata_object in metadata_objects:
        (object_name, obj) = list(metadata_object.items())[0]
        LOG.debug('restoring    object.    backup:    %(backup_id)s,    container:    %(container)s,    object    name:    %(object_name)s,    volume:    %(volume_id)s.', {'backup_id': backup_id, 'container': container, 'object_name': object_name, 'volume_id': volume_id})
        with self.get_object_reader(container, object_name, extra_metadata=extra_metadata) as reader:
            body = reader.read()
        compression_algorithm = metadata_object[object_name]['compression']
        decompressor = self._get_compressor(compression_algorithm)
        volume_file.seek(obj['offset'])
        if (decompressor is not None):
            LOG.debug('decompressing    data    using    %s    algorithm', compression_algorithm)
            decompressed = decompressor.decompress(body)
            volume_file.write(decompressed)
        else:
            volume_file.write(body)
        volume_file.flush()
        try:
            fileno = volume_file.fileno()
        except IOError:
            LOG.info('volume_file    does    not    support    fileno()    so    skipping    fsync()')
        else:
            os.fsync(fileno)
        eventlet.sleep(0)
    LOG.debug('v1    volume    backup    restore    of    %s    finished.', backup_id)
