From fb0858a14cded79b77a3ebe6988c730d259118b6 Mon Sep 17 00:00:00 2001 From: amiller68 Date: Mon, 13 Feb 2023 11:23:47 -0500 Subject: [PATCH 1/3] quick and dirty fix --- src/assert_paths.rs | 54 +++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/src/assert_paths.rs b/src/assert_paths.rs index 41e7c76..f0a4d53 100644 --- a/src/assert_paths.rs +++ b/src/assert_paths.rs @@ -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}, @@ -195,27 +195,43 @@ fn compare_file, PA: AsRef>(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(()) } From 8eec7000f903690a87b4b83faa9d254478793d5b Mon Sep 17 00:00:00 2001 From: amiller68 Date: Mon, 13 Feb 2023 11:25:10 -0500 Subject: [PATCH 2/3] quick fix --- .idea/.gitignore | 5 +++++ .idea/dir-assert.iml | 15 +++++++++++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ 4 files changed, 34 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/dir-assert.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..b58b603 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/dir-assert.iml b/.idea/dir-assert.iml new file mode 100644 index 0000000..cd79d53 --- /dev/null +++ b/.idea/dir-assert.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a8eb4b0 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file From 2e127661b92bbf6101479728bed01c33e6af24e8 Mon Sep 17 00:00:00 2001 From: amiller68 Date: Mon, 13 Feb 2023 11:25:24 -0500 Subject: [PATCH 3/3] quick fix --- .idea/.gitignore | 5 ----- .idea/dir-assert.iml | 15 --------------- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 4 files changed, 34 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/dir-assert.iml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index b58b603..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/dir-assert.iml b/.idea/dir-assert.iml deleted file mode 100644 index cd79d53..0000000 --- a/.idea/dir-assert.iml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index a8eb4b0..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file