Indicate when file has changed on disk

This commit is contained in:
2025-07-09 13:29:22 +02:00
parent 38d26f0028
commit 3a2f058456
8 changed files with 467 additions and 42 deletions

View File

@ -1,6 +1,8 @@
use std::sync::mpsc;
use std::{fs::File, os::unix::fs::MetadataExt as _, sync::mpsc};
use chrono::{DateTime, Local};
use egui::Id;
use eyre::{Context, ContextCompat};
use rand::{Rng, rng};
pub fn random_id() -> Id {
@ -28,3 +30,27 @@ impl<T> GuiSender<T> {
Ok(())
}
}
#[track_caller]
pub fn log_error<T>(chain: eyre::Report, f: impl FnOnce() -> eyre::Result<T>) -> Option<T> {
f().map_err(|e| e.wrap_err(chain))
.inspect_err(|e| log::error!("{e}"))
.ok()
}
pub fn file_mtime(file: &File) -> eyre::Result<DateTime<Local>> {
(move || {
let meta = file.metadata().wrap_err("Failed to stat file")?;
let sec = meta.mtime();
let nsec = meta
.mtime_nsec()
.try_into()
.wrap_err("Nanoseconds overflowed")?;
DateTime::from_timestamp(sec, nsec)
.wrap_err("Bad timestamp")
.map(Into::into)
})()
.wrap_err("Failed to get file mtime")
}