From 2c2788f172116b9486a0e4911f7a9a430abad1ff Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Wed, 22 Jan 2020 18:37:53 -0600 Subject: [PATCH] Update cache when UUID changes If the UUID of the mounted filesystem is different than the cached UUID for that filesystem, the cache needs to be updated with the new value. Otherwise, the program will continually emit warnings once the cached entry expires, regardless of whether or not the filesystem has changed in that time. --- src/cache.rs | 4 ++++ src/main.rs | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cache.rs b/src/cache.rs index 533e27a..99b56cc 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -23,6 +23,10 @@ impl CacheEntry { let now = chrono::Utc::now(); now > self.changed + ttl } + + pub fn uuid(&self) -> &String { + return &self.uuid; + } } #[derive(Serialize, Deserialize, Debug)] diff --git a/src/main.rs b/src/main.rs index 6f4ccc4..1d9d222 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,7 +93,12 @@ fn check_and_notify( match cache { Ok(mut cache) => { if let Some(entry) = cache.get(&mountpoint) { - if entry.expired(ttl) { + if entry.uuid() != uuid { + cache.update(&mountpoint, &uuid); + if let Err(e) = cache.save(&cache_path) { + eprintln!("Failed to save cache: {}", e); + } + } else if entry.expired(ttl) { notify(mountpoint, uuid, entry.changed(), mailto); } } else {