1
0
Fork 0

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.
master
Dustin 2020-01-22 18:37:53 -06:00
parent 636f7dd408
commit 2c2788f172
2 changed files with 10 additions and 1 deletions

View File

@ -23,6 +23,10 @@ impl CacheEntry {
let now = chrono::Utc::now(); let now = chrono::Utc::now();
now > self.changed + ttl now > self.changed + ttl
} }
pub fn uuid(&self) -> &String {
return &self.uuid;
}
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]

View File

@ -93,7 +93,12 @@ fn check_and_notify(
match cache { match cache {
Ok(mut cache) => { Ok(mut cache) => {
if let Some(entry) = cache.get(&mountpoint) { 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); notify(mountpoint, uuid, entry.changed(), mailto);
} }
} else { } else {