mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 00:31:34 +11:00
Use a cache of the changed file
This commit is contained in:
parent
eb26a21629
commit
8a109afee4
|
@ -3,6 +3,7 @@ use proc_macro::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use siphasher::sip::SipHasher;
|
use siphasher::sip::SipHasher;
|
||||||
use std::{
|
use std::{
|
||||||
|
fs,
|
||||||
fs::File,
|
fs::File,
|
||||||
hash::{Hash, Hasher},
|
hash::{Hash, Hasher},
|
||||||
io::Write,
|
io::Write,
|
||||||
|
@ -38,11 +39,26 @@ pub fn include_wav(input: TokenStream) -> TokenStream {
|
||||||
|
|
||||||
let out_file_path = Path::new(&out_dir).with_file_name(&out_filename);
|
let out_file_path = Path::new(&out_dir).with_file_name(&out_filename);
|
||||||
|
|
||||||
let mut out_file = File::create(&out_file_path).expect("Failed to open file for writing");
|
let out_file_mtime = fs::metadata(&out_file_path)
|
||||||
|
.and_then(|metadata| metadata.modified())
|
||||||
|
.ok();
|
||||||
|
let in_file_mtime = fs::metadata(&path)
|
||||||
|
.and_then(|metadata| metadata.modified())
|
||||||
|
.ok();
|
||||||
|
|
||||||
out_file
|
let should_write = match (out_file_mtime, in_file_mtime) {
|
||||||
.write_all(&samples.collect::<Vec<_>>())
|
(Some(out_file_mtime), Some(in_file_mtime)) => out_file_mtime <= in_file_mtime,
|
||||||
.expect("Failed to write to temporary file");
|
_ => true,
|
||||||
|
};
|
||||||
|
|
||||||
|
if should_write {
|
||||||
|
let mut out_file =
|
||||||
|
File::create(&out_file_path).expect("Failed to open file for writing");
|
||||||
|
|
||||||
|
out_file
|
||||||
|
.write_all(&samples.collect::<Vec<_>>())
|
||||||
|
.expect("Failed to write to temporary file");
|
||||||
|
}
|
||||||
|
|
||||||
out_file_path
|
out_file_path
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue