mirror of
https://github.com/uutils/diffutils.git
synced 2026-06-10 15:48:59 -07:00
cmp: use .map_err
This commit is contained in:
+11
-37
@@ -291,27 +291,15 @@ fn prepare_reader(
|
||||
let mut reader: Box<dyn BufRead> = if path == "-" {
|
||||
Box::new(BufReader::new(io::stdin()))
|
||||
} else {
|
||||
match fs::File::open(path) {
|
||||
Ok(file) => Box::new(BufReader::new(file)),
|
||||
Err(e) => {
|
||||
return Err(format_failure_to_read_input_file(
|
||||
¶ms.executable,
|
||||
path,
|
||||
&e,
|
||||
));
|
||||
}
|
||||
}
|
||||
let file = fs::File::open(path)
|
||||
.map_err(|e| format_failure_to_read_input_file(¶ms.executable, path, &e))?;
|
||||
Box::new(BufReader::new(file))
|
||||
};
|
||||
|
||||
if let Some(skip) = skip {
|
||||
// cast as u64 must remain, because value of IgnInit data type could be changed.
|
||||
if let Err(e) = io::copy(&mut reader.by_ref().take(*skip), &mut io::sink()) {
|
||||
return Err(format_failure_to_read_input_file(
|
||||
¶ms.executable,
|
||||
path,
|
||||
&e,
|
||||
));
|
||||
}
|
||||
io::copy(&mut reader.by_ref().take(*skip), &mut io::sink())
|
||||
.map_err(|e| format_failure_to_read_input_file(¶ms.executable, path, &e))?;
|
||||
}
|
||||
|
||||
Ok(reader)
|
||||
@@ -358,27 +346,13 @@ pub fn cmp(params: &Params) -> Result<Cmp, String> {
|
||||
let mut compare = Cmp::Equal;
|
||||
loop {
|
||||
// Fill up our buffers.
|
||||
let from_buf = match from.fill_buf() {
|
||||
Ok(buf) => buf,
|
||||
Err(e) => {
|
||||
return Err(format_failure_to_read_input_file(
|
||||
¶ms.executable,
|
||||
¶ms.from,
|
||||
&e,
|
||||
));
|
||||
}
|
||||
};
|
||||
let from_buf = from
|
||||
.fill_buf()
|
||||
.map_err(|e| format_failure_to_read_input_file(¶ms.executable, ¶ms.from, &e))?;
|
||||
|
||||
let to_buf = match to.fill_buf() {
|
||||
Ok(buf) => buf,
|
||||
Err(e) => {
|
||||
return Err(format_failure_to_read_input_file(
|
||||
¶ms.executable,
|
||||
¶ms.to,
|
||||
&e,
|
||||
));
|
||||
}
|
||||
};
|
||||
let to_buf = to
|
||||
.fill_buf()
|
||||
.map_err(|e| format_failure_to_read_input_file(¶ms.executable, ¶ms.to, &e))?;
|
||||
|
||||
// Check for EOF conditions.
|
||||
if from_buf.is_empty() && to_buf.is_empty() {
|
||||
|
||||
Reference in New Issue
Block a user