From 2e3c1b6a97e03548d1e2c350035c2566ba3e0bde Mon Sep 17 00:00:00 2001 From: networkException Date: Tue, 30 Jul 2024 19:11:40 +0200 Subject: [PATCH] Main: Write failed integrity checks to "restic-integrity-log" --- source/main.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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(())