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(()) }