Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 35 additions & 19 deletions src/assert_paths.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::Error;
use std::fs::{metadata, FileType};
use std::io::{BufRead, BufReader};
use std::io::{BufReader, Read};
use std::{
cmp::Ordering,
fs::{DirEntry, File},
Expand Down Expand Up @@ -195,27 +195,43 @@ fn compare_file<PE: AsRef<Path>, PA: AsRef<Path>>(expected: PE, actual: PA) -> R
let reader_e = BufReader::new(file_e);
let reader_a = BufReader::new(file_a);

for (idx, lines) in reader_e.lines().zip(reader_a.lines()).enumerate() {
let (line_e, line_a) = match lines {
(Ok(line_e), Ok(line_a)) => (line_e, line_a),
(Err(err), _) => {
return Err(Error::new_critical(format!(
"failed reading line from {:?}, reason: {}",
expected, err
)))
}
(_, Err(err)) => {
return Err(Error::new_critical(format!(
"failed reading line from {:?}, reason: {}",
actual, err
)))
}
};

if line_e != line_a {
// Read each reader in fixed sized chunks and compare them -- do not try to read line by line!
// Non-text files will fail to read line by line.
for (idx, (byte_e, byte_a)) in reader_e
.bytes()
.zip(reader_a.bytes())
.enumerate()
.filter(|(_, (byte_e, byte_a))| byte_e.is_ok() && byte_a.is_ok())
{
let (byte_e, byte_a) = (byte_e.unwrap(), byte_a.unwrap());

if byte_e != byte_a {
return Err(Error::new_file_contents_mismatch(expected, actual, idx));
}
}


// for (idx, lines) in reader_e.lines().zip(reader_a.lines()).enumerate() {
// let (line_e, line_a) = match lines {
// (Ok(line_e), Ok(line_a)) => (line_e, line_a),
// (Err(err), _) => {
// return Err(Error::new_critical(format!(
// "failed reading line from {:?}, reason: {}",
// expected, err
// )))
// }
// (_, Err(err)) => {
// return Err(Error::new_critical(format!(
// "failed reading line from {:?}, reason: {}",
// actual, err
// )))
// }
// };
//
// if line_e != line_a {
// return Err(Error::new_file_contents_mismatch(expected, actual, idx));
// }
// }

Ok(())
}