Skip to content
Myr

Use IgnoreDuplicateDirs to prevent duplicate directory traversal

Before adoption: this commit came in with the history the project adopted, so no landing records it.

When --walker=follow is used, symlink following is now handled by fastwalk's IgnoreDuplicateDirs adapter which tracks visited directories by device+inode. This prevents the same directory from being entered more than once, avoiding effectively infinite traversal when a symlink points outside the walker root. Close #4710

authored by Junegunn Choi · committed by Junegunn Choi · parent 2aec7d5 · Browse files · 2 files+9 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+9 added−2 removed

  • other:+9 added−2 removed

2 files+9 added−2 removed

modified:src/reader.go+8 added-2 removed
267 unmodified lines
268}269270func (r *Reader) readFiles(roots []string, opts walkerOpts, ignores []string) bool {271 conf := fastwalk.Config{272 Follow: opts.follow,272 // When opts.follow is true, symlink following and loop/duplicate273 // detection is handled by IgnoreDuplicateDirs below.274 Follow: false,275 // Use forward slashes when running a Windows binary under WSL or MSYS276 ToSlash: fastwalk.DefaultToSlash(),277 Sort: fastwalk.SortFilesFirst,278 }
61 unmodified lines
340 return context.Canceled341 }342 return nil343 }344 var walkFn fs.WalkDirFunc = fn345 if opts.follow {346 walkFn = fastwalk.IgnoreDuplicateDirs(fn)347 }348 noerr := true349 for _, root := range roots {344 noerr = noerr && (fastwalk.Walk(&conf, root, fn) == nil)350 noerr = noerr && (fastwalk.Walk(&conf, root, walkFn) == nil)351 }352 return noerr353}354
29 unmodified lines
modified:CHANGELOG.md+1 added
25 unmodified lines
26 - Improved the cache structure, reducing memory footprint per entry by 86x.27 - With the reduced per-entry cost, the cache now has broader coverage.28- fish: Improved command history (CTRL-R) (#4703) (@bitraid)29- Bug fixes30 - `--walker=follow` no longer visits the same directory more than once. This avoids effectively infinite traversal when a symlink points outside the walker root (#4710)31 - Fixed AWK tokenizer not treating a new line character as whitespace32 - Fixed `--{accept,with}-nth` removing trailing whitespaces with a non-default `--delimiter`33 - Fixed OSC8 hyperlinks being mangled when the URL contains unicode characters (#4707)34 - Fixed `--with-shell` not handling quoted arguments correctly (#4709)
3207 unmodified lines