diff --git a/source/main.rs b/source/main.rs index 79d16c1..64d700b 100644 --- a/source/main.rs +++ b/source/main.rs @@ -1,14 +1,16 @@ /* - * Copyright (c) 2022, networkException + * Copyright (c) 2024, networkException * * 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(())