Skip to content

Commit

Permalink
--walker-skip should also handle symlinks to directories
Browse files Browse the repository at this point in the history
Fix #3858
  • Loading branch information
junegunn committed Jun 13, 2024
1 parent 0acace1 commit 9dc3ed6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"io"
"io/fs"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -222,6 +223,16 @@ func (r *Reader) readFromStdin() bool {
return true
}

func isSymlinkToDir(path string, de os.DirEntry) bool {
if de.Type()&fs.ModeSymlink == 0 {
return false
}
if s, err := os.Stat(path); err == nil {
return s.IsDir()
}
return false
}

func (r *Reader) readFiles(root string, opts walkerOpts, ignores []string) bool {
r.killed = false
conf := fastwalk.Config{Follow: opts.follow}
Expand All @@ -232,7 +243,7 @@ func (r *Reader) readFiles(root string, opts walkerOpts, ignores []string) bool
path = filepath.Clean(path)
if path != "." {
isDir := de.IsDir()
if isDir {
if isDir || opts.follow && isSymlinkToDir(path, de) {
base := filepath.Base(path)
if !opts.hidden && base[0] == '.' {
return filepath.SkipDir
Expand Down

0 comments on commit 9dc3ed6

Please sign in to comment.