mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
CRLF->LF handing in file comparisons
This commit is contained in:
parent
86cc7de6b1
commit
3b9041d8d7
1 changed files with 22 additions and 9 deletions
|
|
@ -232,16 +232,29 @@ 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 f1 = BufReader::new(f1);
|
let s2 = fs::read_to_string(b);
|
||||||
let f2 = BufReader::new(f2);
|
|
||||||
|
|
||||||
// Do a byte to byte comparison of the two files
|
if s1.is_ok() && s2.is_ok() {
|
||||||
for (b1, b2) in f1.bytes().zip(f2.bytes()) {
|
// text do CRLF substitutions
|
||||||
if b1.unwrap() != b2.unwrap() {
|
let f1 = s1?.replace("\r\n", "\n");
|
||||||
return Ok(false);
|
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 f2 = BufReader::new(f2);
|
||||||
|
|
||||||
return Ok(true);
|
// Do a byte to byte comparison of the two files
|
||||||
|
for (b1, b2) in f1.bytes().zip(f2.bytes()) {
|
||||||
|
if b1.unwrap() != b2.unwrap() {
|
||||||
|
return Ok(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue