Main: Write failed integrity checks to "restic-integrity-log"

This commit is contained in:
networkException 2024-07-30 19:11:40 +02:00
parent 0f7b8cf4e5
commit 2e3c1b6a97
Signed by: networkException
GPG key ID: E3877443AE684391

View file

@ -1,14 +1,16 @@
/*
* Copyright (c) 2022, networkException <git@nwex.de>
* Copyright (c) 2024, networkException <git@nwex.de>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
use chrono::Local;
use clap::Parser;
use indicatif::{ParallelProgressIterator, ProgressBar, ProgressStyle, ProgressFinish};
use rayon::ThreadPoolBuilder;
use rayon::iter::{ParallelIterator, IntoParallelRefIterator};
use std::fs::File;
use std::fs::{File, OpenOptions};
use std::io::Write;
use std::path::Path;
use std::io::{self, Result, Error, ErrorKind};
use sha2::{Sha256, Digest};
@ -100,6 +102,20 @@ fn run() -> Result<()> {
let path_string = path.to_str().unwrap();
eprintln!("Integrity check failed for {}: Expected {}, got {}", path_string, filename, hash);
let file = OpenOptions::new()
.create(true)
.append(true)
.open("restic-integrity-log");
match file {
Err(error) => eprintln!("Unable to write to restic-integrity-log: {}", error),
Ok(mut file) => {
if let Err(error) = writeln!(file, "{}: Integrity check failed for {}: Expected {}, got {}", Local::now().format("%Y-%m-%d %H:%M:%S"), path_string, filename, hash) {
eprintln!("Unable to write to restic-integrity-log: {}", error)
}
}
}
}
Ok(())