Repository navigation
Conversation
GNU grep treats `-` as standard input for --exclude-from, as it already does for -f. uu_grep read the operand as a path, so `printf '*.log\n' | grep -rl --exclude-from=- PAT dir` failed with "grep: -: No such file or directory" (exit 2), and silently used a file literally named `-` when one happened to exist. Use the same `-` branch as the -f loop: read stdin and label read errors "(standard input)". Fixes uutils#167 Signed-off-by: bfs2021 <101915083+bfs2021@users.noreply.github.com>
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
| .map_err(|err| read_error("(standard input)", &err))?; | ||
| buf | ||
| } else { | ||
| std::fs::read_to_string(path).map_err(|err| read_error(path, &err))? |
There was a problem hiding this comment.
Please handle the result error in a single place instead of calling read_error twice.
main's GlobSet refactor (one GlobSet for --include, --exclude and --exclude-dir) restructured the surrounding code; resolve the conflict on top of it and address review feedback by reporting read errors from the --exclude-from loop in a single place. Signed-off-by: bfs2021 <101915083+bfs2021@users.noreply.github.com>
|
Merged main (the GlobSet refactor) to clear the conflict, and reworked the |
| ) { | ||
| for (i, path) in indices.zip(paths) { | ||
| let contents = std::fs::read_to_string(path).map_err(|err| read_error(path, &err))?; | ||
| let label = if path == "-" { |
There was a problem hiding this comment.
path == "-" is tested twice, could be a single if returning the label and the result, no?
and it is almost the same code as the -f branch above, could be a small shared helper
| let (scene, mut c) = ucmd(); | ||
| build_tree(&scene); | ||
| c.args(&["-r", "-l", "--exclude-from=-", "grep", "tree"]) | ||
| .pipe_in( |
There was a problem hiding this comment.
please use .pipe_in("*.log\n"), the multi-line literal is hard to read
`-f` and `--exclude-from` each carried their own `-` branch; a shared helper returns the error label and the contents, so the operand is tested once.
|
Both points taken in 37443be: |
Problem
GNU grep reads the exclude list from standard input when the
--exclude-fromoperand is-:uu_grepinstead opened a file literally named-: with no such file it exits 2 withgrep: -: No such file or directory, and if a file named-happens to exist it silently uses that file and never drains the pipe.-f -already reads standard input correctly.Fixes #167
Root cause
uumaininsrc/lib.rshas a-branch for the-fpattern files (src/lib.rs:243-252) but the--exclude-fromloop a few lines below read every operand withstd::fs::read_to_string(path)unconditionally, so"-"was treated as a path.Fix
The
--exclude-fromloop now uses the same-branch as-f: read the list from stdin and label read errors(standard input). Nothing else changes — the patterns still enter the glob list at their command-line position.Testing
exclude_from_dash_reads_standard_inputintests/test_grep.rs:-r -l --exclude-from=-with*.log\npiped on stdin keepsa.txtand dropsb.log. It fails on the previous code (grep: -: No such file or directory, exit 2) and passes with the fix.cargo test: 98 passed, 2 failed —nonexistent_file_error_has_no_os_error_suffixandquiet_match_overrides_file_errorfail identically on a clean checkout here because this machine's Windows is localized (the OS message is系统找不到指定的文件。, the tests expect the English text). Pre-existing, unrelated to this change.cargo fmt --checkandcargo clippy --all-targets: clean.