'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.'

def _UpdateChildIndex(self, urn, token, mutation_pool=None):

    try:
        while (urn.Path() != '/'):
            basename = urn.Basename()
            dirname = rdfvalue.RDFURN(urn.Dirname())
            try:
                self.intermediate_cache.Get(urn)
                return
            except KeyError:
                attributes = {('index:dir/%s' % utils.SmartStr(basename)): [EMPTY_DATA]}
                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
