Skip to content

Commit

Permalink
Auto-renew spec file
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav committed Jan 17, 2025
1 parent 911ff31 commit ee5a12a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions node/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {
Expand All @@ -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());
Expand Down

0 comments on commit ee5a12a

Please sign in to comment.