Allow testnet command to overwrite files (#1045)

This commit is contained in:
Age Manning
2020-04-23 19:01:16 +10:00
committed by GitHub
parent 91648cc230
commit 6784a8b42a
3 changed files with 22 additions and 9 deletions

View File

@@ -64,9 +64,11 @@ impl<E: EthSpec> Eth2TestnetConfig<E> {
})
}
// Write the files to the directory, only if the directory doesn't already exist.
pub fn write_to_file(&self, base_dir: PathBuf) -> Result<(), String> {
if base_dir.exists() {
// Write the files to the directory.
//
// Overwrites files if specified to do so.
pub fn write_to_file(&self, base_dir: PathBuf, overwrite: bool) -> Result<(), String> {
if base_dir.exists() && !overwrite {
return Err("Testnet directory already exists".to_string());
}
@@ -252,7 +254,7 @@ mod tests {
};
testnet
.write_to_file(base_dir.clone())
.write_to_file(base_dir.clone(), false)
.expect("should write to file");
let decoded = Eth2TestnetConfig::load(base_dir).expect("should load struct");