'Add hash digest to tracker and check with filestore.'

@flow.StateHandler()
def ReceiveFileHash(self, responses):

    if ((not responses.success) and (responses.request.request.name == 'HashFile')):
        logging.debug('HashFile    action    not    available,    falling    back    to    FingerprintFile.')
        self.CallClient(server_stubs.FingerprintFile, responses.request.request.payload, next_state='ReceiveFileHash', request_data=responses.request_data)
        return
    index = responses.request_data['index']
    if (not responses.success):
        self.Log('Failed    to    hash    file:    %s', responses.status)
        self.state.pending_hashes.pop(index, None)
        self._FileFetchFailed(index, responses.request.request.name)
        return
    self.state.files_hashed += 1
    response = responses.First()
    if response.HasField('hash'):
        hash_obj = response.hash
    else:
        hash_obj = rdf_crypto.Hash()
        if ((len(response.results) < 1) or (response.results[0]['name'] != 'generic')):
            self.Log('Failed    to    hash    file:    %s', self.state.indexed_pathspecs[index])
            self.state.pending_hashes.pop(index, None)
            return
        result = response.results[0]
        try:
            for hash_type in ['md5', 'sha1', 'sha256']:
                value = result.GetItem(hash_type)
                setattr(hash_obj, hash_type, value)
        except AttributeError:
            self.Log('Failed    to    hash    file:    %s', self.state.indexed_pathspecs[index])
            self.state.pending_hashes.pop(index, None)
            return
    try:
        tracker = self.state.pending_hashes[index]
    except KeyError:
        self._FileFetchFailed(index, responses.request.request.name)
        return
    tracker['hash_obj'] = hash_obj
    tracker['bytes_read'] = response.bytes_read
    self.state.files_hashed_since_check += 1
    if (self.state.files_hashed_since_check >= self.MIN_CALL_TO_FILE_STORE):
        self._CheckHashesWithFileStore()
