def _fs_match(pattern, filename, sep, follow, symlinks):
    """
    Match path against the pattern.

    Since `globstar` doesn't match symlinks (unless `FOLLOW` is enabled), we must look for symlinks.
    If we identify a symlink in a `globstar` match, we know this result should not actually match.
    """

    matched = False

    base = None
    m = pattern.fullmatch(filename)
    if m:
        matched = True
        # Lets look at the captured `globstar` groups and see if that part of the path
        # contains symlinks.
        if not follow:
            groups = m.groups()
            last = len(groups)
            for i, star in enumerate(m.groups(), 1):
                if star:
                    parts = star.strip(sep).split(sep)
                    if base is None:
                        base = filename[:m.start(i)]
                    for part in parts:
                        base = os.path.join(base, part)
                        is_link = symlinks.get(base, None)
                        if is_link is not None:
                            matched = not is_link
                        elif i != last or os.path.isdir(base):
                            is_link = os.path.islink(base)
                            symlinks[base] = is_link
                            matched = not is_link
                        if not matched:
                            break
                if matched:
                    break
    return matched
Match path against the pattern.

    Since `globstar` doesn't match symlinks (unless `FOLLOW` is enabled), we must look for symlinks.
    If we identify a symlink in a `globstar` match, we know this result should not actually match.