def locate_dominating_file(io, filename, directory=None):
    """
    Find a file or directory with the given name, either in the given
    (defaults to current) directory or a parent. Return the full path,
    or None if the root of the filesystem is reached before finding a
    matching file.
    """
    if directory is None:
        directory = io.getcwd()
    last, directory = None, io.realpath(directory)
    while directory != last:
        path = io.join(directory, filename)
        if io.exists(path) or io.islink(path):
            return path
        last, directory = directory, io.dirname(directory)
    return None