From 8c716b2e923c2032107b8a5c6db38c92fdc57bfa Mon Sep 17 00:00:00 2001 From: Akihito Nakano Date: Thu, 19 Mar 2020 09:22:15 +0900 Subject: [PATCH] Fix incomplete build in case of the machine is offline (#935) --- eth2/utils/eth2_testnet_config/build.rs | 32 +++++++++++++++---------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/eth2/utils/eth2_testnet_config/build.rs b/eth2/utils/eth2_testnet_config/build.rs index 8f2817d86a..e2f7d71b39 100644 --- a/eth2/utils/eth2_testnet_config/build.rs +++ b/eth2/utils/eth2_testnet_config/build.rs @@ -8,23 +8,29 @@ use std::path::PathBuf; const TESTNET_ID: &str = "testnet5"; fn main() { - match get_all_files() { - Ok(()) => (), - Err(e) => panic!(e), + if !base_dir().exists() { + std::fs::create_dir_all(base_dir()).expect(&format!("Unable to create {:?}", base_dir())); + + match get_all_files() { + Ok(()) => (), + Err(e) => { + std::fs::remove_dir_all(base_dir()).expect(&format!( + "{}. Failed to remove {:?}, please remove the directory manually because it may contains incomplete testnet data.", + e, + base_dir(), + )); + panic!(e); + } + } } } pub fn get_all_files() -> Result<(), String> { - if !base_dir().exists() { - std::fs::create_dir_all(base_dir()) - .map_err(|e| format!("Unable to create {:?}: {}", base_dir(), e))?; - - get_file("boot_enr.yaml")?; - get_file("config.yaml")?; - get_file("deploy_block.txt")?; - get_file("deposit_contract.txt")?; - get_file("genesis.ssz")?; - } + get_file("boot_enr.yaml")?; + get_file("config.yaml")?; + get_file("deploy_block.txt")?; + get_file("deposit_contract.txt")?; + get_file("genesis.ssz")?; Ok(()) }