kutil_std/fs/modification.rs
1use std::{fs::*, hash::*, io, path::*};
2
3/// Calculates an identifier for a file based on its modification date.
4///
5/// The actual value is intended to be opaque, however it should be unique for every file
6/// modification.
7pub fn file_modification_identifier<PathT>(path: PathT) -> io::Result<u64>
8where
9 PathT: AsRef<Path>,
10{
11 let modified = metadata(path)?.modified()?;
12 let mut hasher = DefaultHasher::new();
13 modified.hash(&mut hasher);
14 Ok(hasher.finish())
15}