Repository navigation
grep: report dangling symlinks and directory loops with -R - #222
yunusarda-sudo wants to merge 5 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #222 +/- ##
==========================================
+ Coverage 97.25% 97.27% +0.02%
==========================================
Files 6 6
Lines 2147 2165 +18
Branches 235 238 +3
==========================================
+ Hits 2088 2106 +18
Misses 59 59
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
|
GNU grep testsuite comparison: |
|
|
||
| let mut c = scene.cmd(env!("CARGO_BIN_EXE_grep")); | ||
| c.args(&["-R", "match", "tree"]) | ||
| .fails_with_code(2) |
There was a problem hiding this comment.
could be stdout_is("tree/sub/hit.txt:match here\n")?
it would also catch the loop being walked twice
There was a problem hiding this comment.
Updated: it now uses stdout_is("tree/sub/hit.txt:match here\n").
|
GNU grep testsuite comparison: |
2 similar comments
|
GNU grep testsuite comparison: |
|
GNU grep testsuite comparison: |
| if err.loop_ancestor().is_some() { | ||
| self.writer.report_recursive_loop(path); | ||
| } else { | ||
| let fallback_err = io::Error::other("walk error"); |
There was a problem hiding this comment.
walkdir always has an io error when it isn't a loop, so this fallback can't happen, no?
else if let Some(io_err) = err.io_error() was fine, no need for a fake "walk error" just for coverage
There was a problem hiding this comment.
Agreed, the fallback could not happen. It now uses else if let Some(io_err) = err.io_error() only.
…g links and cycles
0271a1c to
e978540
Compare
|
GNU grep testsuite comparison: |
Fixes #212
Problem
When recursing with
-R(--dereference-recursive),greppreviously ignored walk errors (let Ok(entry) = entry else { continue; }), which caused dangling symlinks and recursive directory cycles to be silently skipped without warning or setting error exit code 2.Solution
WalkDirinSearcher::process_dir.self.had_error = trueso that the error is reflected in the exit status.err.loop_ancestor().is_some(), callreport_recursive_loopto emitgrep: <path>: warning: recursive directory loopto stderr.err.io_error()is present, callreport_io_errorto emitgrep: <path>: <err>to stderr.-s/--no-messagesis enabled.dereference_recursive_reports_dangling_link_and_loopintests/test_grep.rs.