Teach legdur to understand file moves

main
Cyryl Płotnicki 2022-08-14 09:31:06 +01:00
parent 9aa87c62ee
commit bcd6c4e239
4 changed files with 15 additions and 4 deletions

2
Cargo.lock generated
View File

@ -290,7 +290,7 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "legdur"
version = "0.2.2"
version = "0.3.0"
dependencies = [
"camino",
"hex",

View File

@ -1,7 +1,7 @@
[package]
authors = ["Cyryl Płotnicki <cyplo@cyplo.dev>"]
name = "legdur"
version = "0.2.3"
version = "0.3.0"
edition = "2021"
rust-version = "1.56"
license = "AGPL-3.0"

View File

@ -31,7 +31,7 @@ finished:
## How it works
* it will compute a hash of each file present in the directory structure (it works recursively).
* if previously computed `legdur.db` exists it will compare the current state of the world to the one represented by `legdur.db` and output any differences. Only files that changed or got deleted get printed out, additions are not.
* if previously computed `legdur.db` exists it will compare the current state of the world to the one represented by `legdur.db` and output any differences. Only files that changed or got deleted get printed out, additions or file moves anywhere within the directory are not.
* it will move the current `legdur.db` to `legdur.old` and write the new state of the world to a new `legdur.db`
## Contact & contributions

View File

@ -56,7 +56,18 @@ fn compare_with_old(old_database_path: &Utf8PathBuf, database_path: &Utf8PathBuf
old_db
.into_par_iter()
.for_each(|(key, old_value)| match new_db.get(&key) {
None => warn!("{key} does not exist anymore"),
None => {
// FIXME probably better to store reverse hash in db as well
// instead of searching every time
match new_db
.par_iter()
.find_any(|(_, new_value)| *new_value == &old_value)
{
Some(_) => { //file moved elsewhere but still exists
}
None => warn!("{key} does not exist anymore"),
}
}
Some(new_value) => {
if new_value != &old_value {
warn!("{key}: {old_value} -> {new_value}")