Skip to content

Commit d0f980b

Browse files
committed
Release 0.2.0 and support binary files
While fixing #3, I realized I had some stuff backwards. I don't know why exactly, but now things should be good. Fixes #3.
1 parent bab279e commit d0f980b

File tree

7 files changed

+21
-17
lines changed

7 files changed

+21
-17
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
authors = ["steveklabnik <steve@steveklabnik.com>"]
33
name = "dir-diff"
4-
version = "0.1.0"
4+
version = "0.2.0"
55
description = "Do two directories have different contents?"
66
license = "MIT/Apache-2.0"
77
repository = "https://github.com/steveklabnik/dir-diff"
@@ -10,5 +10,4 @@ readme = "README.md"
1010
tags = ["directory", "diff", "fs"]
1111

1212
[dependencies]
13-
diff = "0.1.10"
1413
walkdir = "1.0.7"

src/lib.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//! assert!(dir_diff::is_different("dir/a", "dir/b").unwrap());
1212
//! ```
1313
14-
extern crate diff;
1514
extern crate walkdir;
1615

1716
use std::fs::File;
@@ -61,25 +60,21 @@ pub fn is_different<A: AsRef<Path>, B: AsRef<Path>>(a_base: A, b_base: B) -> Res
6160
}
6261
}
6362

64-
let a_text = read_to_string(a)?;
65-
let b_text = read_to_string(b)?;
63+
let a_text = read_to_vec(a)?;
64+
let b_text = read_to_vec(b)?;
6665

67-
for result in diff::lines(&a_text, &b_text) {
68-
match result {
69-
diff::Result::Both(..) => (),
70-
_ => return Ok(false),
71-
}
66+
if a_text != b_text {
67+
return Ok(true);
7268
}
7369
}
74-
75-
Ok(true)
70+
Ok(false)
7671
}
7772

78-
fn read_to_string<P: AsRef<Path>>(file: P) -> Result<String, std::io::Error> {
79-
let mut data = String::new();
73+
fn read_to_vec<P: AsRef<Path>>(file: P) -> Result<Vec<u8>, std::io::Error> {
74+
let mut data = Vec::new();
8075
let mut file = File::open(file.as_ref())?;
8176

82-
file.read_to_string(&mut data)?;
77+
file.read_to_end(&mut data)?;
8378

8479
Ok(data)
8580
}
93.8 KB
Loading
128 KB
Loading
93.8 KB
Loading
93.8 KB
Loading

tests/smoke.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@ extern crate dir_diff;
22

33
#[test]
44
fn easy_good() {
5-
assert!(dir_diff::is_different("tests/easy/good/dir1", "tests/easy/good/dir2").unwrap());
5+
assert!(!dir_diff::is_different("tests/easy/good/dir1", "tests/easy/good/dir2").unwrap());
66
}
77

88
#[test]
99
fn easy_bad() {
10-
assert!(!dir_diff::is_different("tests/easy/bad/dir1", "tests/easy/bad/dir2").unwrap());
10+
assert!(dir_diff::is_different("tests/easy/bad/dir1", "tests/easy/bad/dir2").unwrap());
11+
}
12+
13+
#[test]
14+
fn binary_good() {
15+
assert!(!dir_diff::is_different("tests/binary/good/dir1", "tests/binary/good/dir2").unwrap());
16+
}
17+
18+
#[test]
19+
fn binary_bad() {
20+
assert!(dir_diff::is_different("tests/binary/bad/dir1", "tests/binary/bad/dir2").unwrap());
1121
}

0 commit comments

Comments
 (0)