use std::{path::PathBuf, time::SystemTime};
use tokio::fs;
use crate::{Error, ErrorKind};
pub fn make_error_mapper<E: std::fmt::Display + 'static>(
kind: ErrorKind,
) -> impl FnOnce(E) -> Error {
move |error| Error {
kind,
message: error.to_string(),
}
}
pub async fn get_mtime(path: &PathBuf) -> Result<u128, Error> {
let value = fs::metadata(path)
.await
.map_err(make_error_mapper(ErrorKind::ErrorReadingFile))?
.modified()
.map_err(make_error_mapper(ErrorKind::ErrorReadingFile))?
.duration_since(SystemTime::UNIX_EPOCH)
.map_err(make_error_mapper(ErrorKind::ErrorReadingFile))?;
Ok(value.as_millis())
}