CRLF->LF handing in file comparisons

This commit is contained in:
bunnie 2022-10-05 21:20:16 +08:00
parent 86cc7de6b1
commit 3b9041d8d7

View file

@ -232,7 +232,20 @@ fn compare_files(a: &Path, b: &Path) -> Result<bool, DynError> {
return Ok(false); return Ok(false);
} }
// Use buf readers since they are much faster let s1 = fs::read_to_string(a);
let s2 = fs::read_to_string(b);
if s1.is_ok() && s2.is_ok() {
// text do CRLF substitutions
let f1 = s1?.replace("\r\n", "\n");
let f2 = s2?.replace("\r\n", "\n");
if f1 == f2 {
Ok(true)
} else {
Ok(false)
}
} else {
// do a binary compare
let f1 = BufReader::new(f1); let f1 = BufReader::new(f1);
let f2 = BufReader::new(f2); let f2 = BufReader::new(f2);
@ -242,6 +255,6 @@ fn compare_files(a: &Path, b: &Path) -> Result<bool, DynError> {
return Ok(false); return Ok(false);
} }
} }
Ok(true)
return Ok(true); }
} }