csplit print 0 on an error like gnu does#13206
Conversation
Merging this PR will degrade performance by 4.67%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
| if let Err(ref e) = res { | ||
| uucore::show_error!("{}", e); | ||
| println!("0"); | ||
| std::process::exit(1); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| let file = File::open(file_name) | ||
| .map_err_context(|| format!("cannot open {} for reading", file_name.quote()))?; | ||
| Ok(csplit(&options, &patterns, BufReader::new(file))?) | ||
| .map_err_context(|| format!("cannot open {} for reading", file_name.quote())); | ||
|
|
||
| match file { | ||
| Ok(f) => csplit(&options, &patterns, BufReader::new(f)).map_err(Into::into), | ||
| Err(e) => Err(e), | ||
| } | ||
| }; |
There was a problem hiding this comment.
probably more something like:
let res = if file_name == "-" {
let stdin = io::stdin();
csplit(&options, &patterns, stdin.lock()).map_err(Into::into)
} else {
File::open(file_name)
.map_err_context(|| format!("cannot open {} for reading", file_name.quote()))
.and_then(|file| csplit(&options, &patterns, BufReader::new(file)).map_err(Into::into))
};
|
GNU testsuite comparison: |
| // Print 0 second | ||
| let stdout = io::stdout(); | ||
| let mut handle = stdout.lock(); | ||
| let _ = writeln!(handle, "0"); |
There was a problem hiding this comment.
GNU catches write error of stdout and ignore write error of stderr (with few expections).
Also lock() is not useful since write is done just once at here.
There was a problem hiding this comment.
so if that, that was a bit complicated, not all errors gnu print 0, that was the issue making it harder, what type of error it do that, we need known
fixes #13139