use std::fs;
use std::path::Path;
use std::time::SystemTime;
use crate::error::DocError;
use crate::walk;
pub(crate) fn is_up_to_date(
output_path: &Path,
md_mtime: SystemTime,
template_mtime: Option<SystemTime>,
) -> Result<bool, DocError> {
let Ok(output_meta) = fs::metadata(output_path) else {
return Ok(false);
};
let output_mtime = output_meta.modified()?;
let newest_input = match template_mtime {
Some(t) if t > md_mtime => t,
_ => md_mtime,
};
Ok(output_mtime >= newest_input)
}
pub(crate) fn latest_mtime(dir: &Path, extension: &str) -> Result<Option<SystemTime>, DocError> {
let mut latest: Option<SystemTime> = None;
for path in walk::walk_files_with_extension(dir, extension)? {
let mtime = fs::metadata(&path)?.modified()?;
latest = Some(match latest {
Some(l) if l > mtime => l,
_ => mtime,
});
}
Ok(latest)
}
#[cfg(test)]
#[path = "../tests/unit/cache.rs"]
mod tests;