From ee5a12a622454eaee261996e4525384534bd537e Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Fri, 17 Jan 2025 09:32:47 +0800 Subject: [PATCH] Auto-renew spec file --- node/src/chain_spec/mod.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/node/src/chain_spec/mod.rs b/node/src/chain_spec/mod.rs index cf972084a..25f81b12d 100644 --- a/node/src/chain_spec/mod.rs +++ b/node/src/chain_spec/mod.rs @@ -138,8 +138,7 @@ where { let d = env::current_exe().unwrap().parent().unwrap().to_path_buf(); let p = d.join(name); - - if !p.is_file() { + let download = || { println!("Downloading `{name}` to `{}`", d.display()); thread::spawn(move || { @@ -156,6 +155,21 @@ where }) .join() .unwrap(); + }; + + if !p.is_file() { + download(); + } else if let Ok(metadata) = p.metadata() { + // Fetch the latest spec every 14 days. + if let Ok(date) = metadata.modified() { + if let Ok(elapsed) = date.elapsed() { + if elapsed.as_secs() > 60 * 60 * 24 * 14 { + if fs::remove_file(p.clone()).is_ok() { + download(); + } + } + } + } } println!("Loading genesis from `{}`", p.display());