def _UpdateChildIndex(self, urn, token, mutation_pool=None):
    """Update the child indexes.

    This function maintains the index for direct child relations. When we set
    an AFF4 path, we always add an attribute like
    index:dir/%(childname)s to its parent. This is written
    asynchronously to its parent.

    In order to query for all direct children of an AFF4 object, we then simple
    get the attributes which match the regex index:dir/.+ which are the
    direct children.

    Args:
      urn: The AFF4 object for which we update the index.
      token: The token to use.
      mutation_pool: An optional MutationPool object to write to. If not given,
                     the data_store is used directly.
    """
    try:
      # Create navigation aids by touching intermediate subject names.
      while urn.Path() != "/":
        basename = urn.Basename()
        dirname = rdfvalue.RDFURN(urn.Dirname())

        try:
          self.intermediate_cache.Get(urn)
          return
        except __HOLE__:
          attributes = {
              # This updates the directory index.
              "index:dir/%s" % utils.SmartStr(basename): [EMPTY_DATA],
          }
          # This is a performance optimization. On the root there is no point
          # setting the last access time since it gets accessed all the time.
          # TODO(user): Can we get rid of the index in the root node entirely?
          # It's too big to query anyways...
          if dirname != u"/":
            attributes[AFF4Object.SchemaCls.LAST] = [
                rdfvalue.RDFDatetime().Now().SerializeToDataStore()]

          if mutation_pool:
            mutation_pool.MultiSet(dirname, attributes, replace=True)
          else:
            data_store.DB.MultiSet(dirname, attributes,
                                   token=token, replace=True, sync=False)

          self.intermediate_cache.Put(urn, 1)

          urn = dirname

    except access_control.UnauthorizedAccess:
      pass
dataset/ETHPy150Open google/grr/grr/lib/aff4.py/Factory._UpdateChildIndex