Persists information about stat entries.

  Args:
    stat_entries: A list of `StatEntry` instances.
    client_id: An id of a client the stat entries come from.
    mutation_pool: A mutation pool used for writing into the AFF4 data store.
    token: A token used for writing into the AFF4 data store.

def WriteStatEntries(stat_entries, client_id, mutation_pool, token=None):
  """Persists information about stat entries.

  Args:
    stat_entries: A list of `StatEntry` instances.
    client_id: An id of a client the stat entries come from.
    mutation_pool: A mutation pool used for writing into the AFF4 data store.
    token: A token used for writing into the AFF4 data store.
  """

  for stat_response in stat_entries:
    if stat_response.pathspec.last.stream_name:
      # This is an ads. In that case we always need to create a file or
      # we won't be able to access the data. New clients send the correct mode
      # already but to make sure, we set this to a regular file anyways.
      # Clear all file type bits:
      stat_response.st_mode &= ~stat_type_mask
      stat_response.st_mode |= stat.S_IFREG

  if data_store.AFF4Enabled():
    for stat_entry in stat_entries:
      CreateAFF4Object(
          stat_entry,
          client_id_urn=rdf_client.ClientURN(client_id),
          mutation_pool=mutation_pool,
          token=token)

  if data_store.RelationalDBEnabled():
    path_infos = [rdf_objects.PathInfo.FromStatEntry(s) for s in stat_entries]
    # NOTE: TSK may return duplicate entries. This is may be either due to
    # a bug in TSK implementation, or due to the fact that TSK is capable
    # of returning deleted files information. Our VFS data model only supports
    # storing multiple versions of the files when we collect the versions
    # ourselves. At the moment we can't store multiple versions of the files
    # "as returned by TSK".
    #
    # Current behaviour is to simply drop excessive version before the
    # WritePathInfo call. This way files returned by TSK will still make it
    # into the flow's results, but not into the VFS data.
    data_store.REL_DB.WritePathInfos(client_id,
                                     _FilterOutPathInfoDuplicates(path_infos))