walk/walk.go
func (r *symlinkResolver) follow(c *config.Config, dir, rel, base string) bool {
	if dir == c.RepoRoot && strings.HasPrefix(base, "bazel-") {
		// Links such as bazel-<workspace>, bazel-out, bazel-genfiles are created by
		// Bazel to point to internal build directories.
		return false
	}

	// See if the user has explicitly directed us to follow the link.
	wc := getWalkConfig(c)
	linkRel := path.Join(rel, base)
	for _, follow := range wc.follow {
		if linkRel == follow {
			return true
		}
	}

	// See if the symlink points to a tree that has been already visited.
	fullpath := filepath.Join(dir, base)
	dest, err := filepath.EvalSymlinks(fullpath)
	if err != nil {
		return false
	}
	if !filepath.IsAbs(dest) {
		dest, err = filepath.Abs(filepath.Join(dir, dest))
		if err != nil {
			return false
		}
	}
	for _, p := range r.visited {
		if pathtools.HasPrefix(dest, p) || pathtools.HasPrefix(p, dest) {
			return false
		}
	}
	r.visited = append(r.visited, dest)
	stat, err := os.Stat(fullpath)
	if err != nil {
		return false
	}
	return stat.IsDir()
}
func (r *symlinkResolver) follow(c *config.Config, dir, rel, base string) bool {
	if dir == c.RepoRoot && strings.HasPrefix(base, "bazel-") {
		// Links such as bazel-<workspace>, bazel-out, bazel-genfiles are created by
		// Bazel to point to internal build directories.
		return false
	}

	// See if the user has explicitly directed us to follow the link.
	wc := getWalkConfig(c)
	linkRel := path.Join(rel, base)
	for _, follow := range wc.follow {
		if linkRel == follow {
			return true
		}
	}

	// See if the symlink points to a tree that has been already visited.
	fullpath := filepath.Join(dir, base)
	dest, err := filepath.EvalSymlinks(fullpath)
	if err != nil {
		return false
	}
	if !filepath.IsAbs(dest) {
		dest, err = filepath.Abs(filepath.Join(dir, dest))
		if err != nil {
			return false
		}
	}
	for _, p := range r.visited {
		if pathtools.HasPrefix(dest, p) || pathtools.HasPrefix(p, dest) {
			return false
		}
	}
	r.visited = append(r.visited, dest)
	stat, err := os.Stat(fullpath)
	if err != nil {
		return false
	}
	return stat.IsDir()
}
// Decide if symlink dir/base should be followed.