fix: fix test and linting fails

Signed-off-by: ronantakizawa <ronantakizawa@gmail.com>
pull/13293/head
ronantakizawa 1 year ago
parent 9b478d5ac2
commit 85403563b3

@ -25,7 +25,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"sort" "sort"
) )
// Walk walks the file tree rooted at root, calling walkFn for each file or directory // Walk walks the file tree rooted at root, calling walkFn for each file or directory
@ -75,7 +74,10 @@ func symwalk(path string, info os.FileInfo, walkFn filepath.WalkFunc) error {
if info, err = os.Lstat(resolved); err != nil { if info, err = os.Lstat(resolved); err != nil {
return err return err
} }
return symwalk(resolved, info, walkFn) if err := symwalk(path, info, walkFn); err != nil && err != filepath.SkipDir { // Notice we pass the original `path` here
return err
}
return nil
} }
if err := walkFn(path, info, nil); err != nil { if err := walkFn(path, info, nil); err != nil {

@ -101,34 +101,22 @@ func (r *Rules) Ignore(path string, fi os.FileInfo) bool {
if path == "." || path == "./" { if path == "." || path == "./" {
return false return false
} }
// Check for symlink and ignore based on pattern
if fi.Mode()&os.ModeSymlink != 0 {
resolvedPath, err := filepath.EvalSymlinks(path)
if err != nil {
log.Printf("Ignoring broken symlink: %s -> %s", path, resolvedPath) // Log and ignore broken symlink
return false // Skip this symlink and continue
}
for _, p := range r.patterns { for _, p := range r.patterns {
if p.match == nil { if p.match == nil {
log.Printf("ignore: no matcher supplied for %q", p.raw) log.Printf("ignore: no matcher supplied for %q", p.raw)
return false return false
} }
// For negative rules, we need to capture and return non-matches,
// and continue for matches.
if p.negate {
if p.mustDir && !fi.IsDir() { if p.mustDir && !fi.IsDir() {
continue
}
if p.match(resolvedPath, fi) {
log.Printf("Ignoring symlink path: %s", path)
return true return true
} }
if !p.match(path, fi) {
return true
} }
return false // Skip further evaluation for this symlink continue
}
for _, p := range r.patterns {
if p.match == nil {
log.Printf("ignore: no matcher supplied for %q", p.raw)
return false
} }
// If the rule is looking for directories, and this is not a directory, // If the rule is looking for directories, and this is not a directory,
@ -141,6 +129,7 @@ func (r *Rules) Ignore(path string, fi os.FileInfo) bool {
} }
} }
return false return false
} }
// parseRule parses a rule string and creates a pattern, which is then stored in the Rules object. // parseRule parses a rule string and creates a pattern, which is then stored in the Rules object.

Loading…
Cancel
Save