Skip to content

Commit

Permalink
accounts-db-tools/add option of file_diff to hash cache tool diff dir…
Browse files Browse the repository at this point in the history
…ectory (anza-xyz#1969)

* add option of file_diff to hash cache tool

* Update accounts-db/accounts-hash-cache-tool/src/main.rs

Co-authored-by: Brooks <brooks@prumo.org>

* Update accounts-db/accounts-hash-cache-tool/src/main.rs

Co-authored-by: Brooks <brooks@prumo.org>

* Update accounts-db/accounts-hash-cache-tool/src/main.rs

Co-authored-by: Brooks <brooks@prumo.org>

* Update accounts-db/accounts-hash-cache-tool/src/main.rs

Co-authored-by: Brooks <brooks@prumo.org>

* Update accounts-db/accounts-hash-cache-tool/src/main.rs

Co-authored-by: Brooks <brooks@prumo.org>

* Update accounts-db/accounts-hash-cache-tool/src/main.rs

Co-authored-by: Brooks <brooks@prumo.org>

* Update accounts-db/accounts-hash-cache-tool/src/main.rs

Co-authored-by: Brooks <brooks@prumo.org>

* Update accounts-db/accounts-hash-cache-tool/src/main.rs

Co-authored-by: Brooks <brooks@prumo.org>

---------

Co-authored-by: HaoranYi <haoran.yi@anza.xyz>
Co-authored-by: Brooks <brooks@prumo.org>
  • Loading branch information
3 people authored Jul 2, 2024
1 parent 1d9d6fd commit f689ac1
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions accounts-db/accounts-hash-cache-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ fn main() {
.takes_value(true)
.value_name("PATH2")
.help("Accounts hash cache directory 2 to diff"),
)
.arg(
Arg::with_name("then_diff_files")
.long("then-diff-files")
.takes_value(false)
.help("After diff-ing the directories, diff the files that were found to have mismatches"),
),
),
)
Expand Down Expand Up @@ -144,7 +150,8 @@ fn cmd_diff_dirs(
) -> Result<(), String> {
let path1 = value_t_or_exit!(subcommand_matches, "path1", String);
let path2 = value_t_or_exit!(subcommand_matches, "path2", String);
do_diff_dirs(path1, path2)
let then_diff_files = subcommand_matches.is_present("then_diff_files");
do_diff_dirs(path1, path2, then_diff_files)
}

fn do_inspect(file: impl AsRef<Path>, force: bool) -> Result<(), String> {
Expand Down Expand Up @@ -291,7 +298,11 @@ fn do_diff_files(file1: impl AsRef<Path>, file2: impl AsRef<Path>) -> Result<(),
Ok(())
}

fn do_diff_dirs(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) -> Result<(), String> {
fn do_diff_dirs(
dir1: impl AsRef<Path>,
dir2: impl AsRef<Path>,
then_diff_files: bool,
) -> Result<(), String> {
let get_files_in = |dir: &Path| {
let mut files = Vec::new();
let entries = fs::read_dir(dir)?;
Expand Down Expand Up @@ -447,6 +458,18 @@ fn do_diff_dirs(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) -> Result<(), St
file2.0 .0.display(),
);
}
if then_diff_files {
for (file1, file2) in &mismatches {
println!(
"Differences between '{}' and '{}':",
file1.0 .0.display(),
file2.0 .0.display(),
);
if let Err(err) = do_diff_files(&file1.0 .0, &file2.0 .0) {
eprintln!("Error: failed to diff files: {err}");
}
}
}
}

Ok(())
Expand Down

0 comments on commit f689ac1

Please sign in to comment.