mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-07-10 17:29:06 +02:00
minedmap: skip generation steps when the inputs are unchanged
This commit is contained in:
parent
6077138292
commit
80781c9c20
4 changed files with 97 additions and 50 deletions
18
src/io/fs.rs
18
src/io/fs.rs
|
@ -6,12 +6,12 @@ use std::{
|
|||
};
|
||||
|
||||
use anyhow::{Context, Ok, Result};
|
||||
use serde::Serialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize)]
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct FileMetaVersion(pub u32);
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct FileMeta {
|
||||
version: FileMetaVersion,
|
||||
timestamp: SystemTime,
|
||||
|
@ -115,6 +115,18 @@ pub fn modified_timestamp(path: &Path) -> Result<SystemTime> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn read_timestamp(path: &Path, version: FileMetaVersion) -> Option<SystemTime> {
|
||||
let meta_path = metafile_name(path);
|
||||
let mut file = BufReader::new(fs::File::open(meta_path).ok()?);
|
||||
|
||||
let meta: FileMeta = serde_json::from_reader(&mut file).ok()?;
|
||||
if meta.version != version {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(meta.timestamp)
|
||||
}
|
||||
|
||||
pub fn create_with_timestamp<T, F>(
|
||||
path: &Path,
|
||||
version: FileMetaVersion,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue