def _update_fileids(delta, fileids, stop_on):
    """Update the set of file-ids to search based on file lifecycle events.

    :param fileids: a set of fileids to update
    :param stop_on: either 'add' or 'remove' - take file-ids out of the
      fileids set once their add or remove entry is detected respectively
    """
    if stop_on == 'add':
        for item in delta.added:
            if item[1] in fileids:
                fileids.remove(item[1])
    elif stop_on == 'delete':
        for item in delta.removed:
            if item[1] in fileids:
                fileids.remove(item[1])
