assert-rs / dir-diff Goto Github PK
View Code? Open in Web Editor NEWDo two directories have different contents?
Home Page: https://docs.rs/dir-diff
License: Apache License 2.0
Do two directories have different contents?
Home Page: https://docs.rs/dir-diff
License: Apache License 2.0
dir-diff version: 0.3.0
rust version: 1.25.0-nightly
OS: Linux
The latest version on Cargo is 0.3.0
, but it's apparently not available. I'm not sure what to do about it, but maybe it was unpublished / something went wrong when deploying? 0.2.0
installs fine.
Maybe releasing a 0.4.0
might work so the latest version on cargo points to a valid release?
I've got my own home grown tool for diffing directories but I'd much have a reusable crate.
API Ideas:
LeftExists
, RightExists
, BothExist(Option<Difference>)
diff_dir_list(path, path)
provides an iterator of (path, enum(None))
diff_dir(path, path)
provides an iterator of (path, enum)
difference
like [assert_cli
](assert_dir_eq!
panic
on first failure or summarize the all differences)From https://github.com/azerupi/mdBook/pull/237#issuecomment-294225041:
Ahh, line endings are the issue here.... I made this PR on Windows, so windows stuff succeeds, but linux stuff fails. Hrm.
..... I am not sure how to fix this, given that if I change it the other way, it will fail on Windows. Hrm.
Ideas:
lines()
on the files and compare over the lines?diff
and use --strip-trailing-cr
(idk the windows equivalent though)and this should probably also be an option, not the default?
dir-diff
depends on dir-diff
instead of walkdir
on crates.io
See
{"name":"dir-diff","vers":"0.3.0","deps":[{"name":"dir-diff","req":"^1.0.7","features":[],"optional":false,"default_features":true,"target":null,"kind":"normal"}],"cksum":"f0ebe1d95170b79f6775ad44c058eeccc004eaa86cb78e8b7c6abab407d3235e","features":{},"yanked":false}
From https://github.com/rust-lang/crates.io-index/blob/master/di/r-/dir-diff
This means non-utf8 files can't work
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates await pending status checks. To force their creation now, click the checkbox below.
Cargo.toml
walkdir 2.0.1
.github/workflows/audit.yml
actions/checkout v4
actions-rs/audit-check v1
actions/checkout v4
EmbarkStudios/cargo-deny-action v1
.github/workflows/ci.yml
actions/checkout v4
Swatinem/rust-cache v2
actions/checkout v4
Swatinem/rust-cache v2
actions/checkout v4
Swatinem/rust-cache v2
actions/checkout v4
Swatinem/rust-cache v2
actions/checkout v4
Swatinem/rust-cache v2
actions/checkout v4
Swatinem/rust-cache v2
github/codeql-action v3
.github/workflows/committed.yml
actions/checkout v4
.github/workflows/pre-commit.yml
actions/checkout v4
actions/setup-python v5
pre-commit/action v3.0.0
.github/workflows/rust-next.yml
actions/checkout v4
Swatinem/rust-cache v2
actions/checkout v4
Swatinem/rust-cache v2
.github/workflows/spelling.yml
actions/checkout v4
.clippy.toml
rust 1.66
.github/workflows/ci.yml
rust 1.66
rust 1.66
rust 1.66
Cargo.toml
rust 1.66
The code below loads both files completely into memory before comparing. For files that differ early that can be quite wasteful and it can also result in out of memory errors.
// file a is guaranteed to exist...
let a_text = read_to_vec(a)?;
// but file b is not. If we have any kind of error when loading
// it up, that's a positive result, not an actual error.
let b_text = match read_to_vec(b) {
Ok(contents) => contents,
Err(_) => return Ok(true),
};
if a_text != b_text {
return Ok(true);
}
I'd propose something like
let a_reader = BufReader::new( File::open(a)? );
let b_reader = match File::open(a) {
Ok(f) => BufReader::new(f),
Err(_) => return Ok(true),
}
if a_reader.bytes().ne( b_reader.bytes() ) {
return Ok(true)
}
for similar functionality. The above won't compile when I'm reading the docs right, because the Bytes
iterator returns Result<u8, io::Error>
and io::Error
doesn't implement PartialEq
but one should be able to manually iterate in lockstep like so
let mut a_bytes = a_reader.bytes();
let mut b_bytes = b_reader.bytes();
loop {
match (a_bytes().next(), b_bytes().next()) {
(Some(Ok(a)), Some(Ok(b))) => if a != b { return Ok(true) },
(None, None) => break,
_ => return Ok(true),
}
}
Now, you're also treating any kind of error as if that would indicate a difference in the folders but there's so much that can go wrong in the world that you can't really make that decision. It's certainly true for FileNotFound
but what about some network storage that loses connection for example?
I don't know how much of that ugly mess you're willing to deal with of course.
Note: All code untested. I'm not at a full fledged PC at the moment
Hi!
This crate looks very similar to what we did in checksumdir, which is a straight port of python's checksumdir, and diff-rs in order to make those functions available to Torchbear's scripting environment - just announced in r/rust.
Perhaps someone here would like to try out this new Rust project that makes it possible to produce useful apps from powerful libraries in simple scripts.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.