pub fn force_write_to_file(&self, base_dir: PathBuf) -> Result<(), String> {
        create_dir_all(&base_dir)
            .map_err(|e| format!("Unable to create testnet directory: {:?}", e))?;

        macro_rules! write_to_yaml_file {
            ($file: ident, $variable: expr) => {
                File::create(base_dir.join($file))
                    .map_err(|e| format!("Unable to create {}: {:?}", $file, e))
                    .and_then(|mut file| {
                        let yaml = serde_yaml::to_string(&$variable)
                            .map_err(|e| format!("Unable to YAML encode {}: {:?}", $file, e))?;

                        // Remove the doc header from the YAML file.
                        //
                        // This allows us to play nice with other clients that are expecting
                        // plain-text, not YAML.
                        let no_doc_header = if let Some(stripped) = yaml.strip_prefix("---\n") {
                            stripped
                        } else {
                            &yaml
                        };

                        file.write_all(no_doc_header.as_bytes())
                            .map_err(|e| format!("Unable to write {}: {:?}", $file, e))
                    })?;
            };
        }

        write_to_yaml_file!(DEPLOY_BLOCK_FILE, self.deposit_contract_deploy_block);

        if let Some(boot_enr) = &self.boot_enr {
            write_to_yaml_file!(BOOT_ENR_FILE, boot_enr);
        }

        if let Some(yaml_config) = &self.yaml_config {
            write_to_yaml_file!(YAML_CONFIG_FILE, yaml_config);
        }

        // The genesis state is a special case because it uses SSZ, not YAML.
        if let Some(genesis_state_bytes) = &self.genesis_state_bytes {
            let file = base_dir.join(GENESIS_STATE_FILE);

            File::create(&file)
                .map_err(|e| format!("Unable to create {:?}: {:?}", file, e))
                .and_then(|mut file| {
                    file.write_all(genesis_state_bytes)
                        .map_err(|e| format!("Unable to write {:?}: {:?}", file, e))
                })?;
        }

        Ok(())
    }
/// Write the files to the directory, even if the directory already exists.
Write the files to the directory, even if the directory already exists.
Write the files to the directory even if the directory already exists .
pub fn force_write_to_file(&self, base_dir: PathBuf) -> Result<(), String> {
        create_dir_all(&base_dir)
            .map_err(|e| format!("Unable to create testnet directory: {:?}", e))?;
        macro_rules! write_to_yaml_file {
            ($file: ident, $variable: expr) => {
                File::create(base_dir.join($file))
                    .map_err(|e| format!("Unable to create {}: {:?}", $file, e))
                    .and_then(|mut file| {
                        let yaml = serde_yaml::to_string(&$variable)
                            .map_err(|e| format!("Unable to YAML encode {}: {:?}", $file, e))?;
                        // Remove the doc header from the YAML file.
                        //
                        // This allows us to play nice with other clients that are expecting
                        // plain-text, not YAML.
                        let no_doc_header = if let Some(stripped) = yaml.strip_prefix("---\n") {
                            stripped
                        } else {
                            &yaml
                        };
                        file.write_all(no_doc_header.as_bytes())
                            .map_err(|e| format!("Unable to write {}: {:?}", $file, e))
                    })?;
            };
        }
        write_to_yaml_file!(DEPLOY_BLOCK_FILE, self.deposit_contract_deploy_block);
        if let Some(boot_enr) = &self.boot_enr {
            write_to_yaml_file!(BOOT_ENR_FILE, boot_enr);
        }
        if let Some(yaml_config) = &self.yaml_config {
            write_to_yaml_file!(YAML_CONFIG_FILE, yaml_config);
        }
        // The genesis state is a special case because it uses SSZ, not YAML.
        if let Some(genesis_state_bytes) = &self.genesis_state_bytes {
            let file = base_dir.join(GENESIS_STATE_FILE);
            File::create(&file)
                .map_err(|e| format!("Unable to create {:?}: {:?}", file, e))
                .and_then(|mut file| {
                    file.write_all(genesis_state_bytes)
                        .map_err(|e| format!("Unable to write {:?}: {:?}", file, e))
                })?;
        }
        Ok(())
    }
pub fn force_write_to_file ( & self , base_dir : PathBuf ) -> Result < ( ) , String > { create_dir_all ( & base_dir ) . map_err ( | e | format ! ( " " e ) ) ? ; macro_rules! write_to_yaml_file { ( $file : ident $variable : expr ) => { File create ( base_dir join ( $file ) ) map_err ( e format ( " " $file e ) ) and_then ( mut file { let yaml serde_yaml to_string ( $variable ) map_err ( e format ( " " $file e ) ) // Remove the doc header from the YAML file. // This allows us to play nice with other clients that are expecting // plain-text, not YAML. let no_doc_header if let Some ( stripped ) yaml strip_prefix ( " \n " ) { stripped } else { yaml } file write_all ( no_doc_header as_bytes ( ) ) map_err ( e format ( " " $file e ) ) } ) } ; } write_to_yaml_file ! ( DEPLOY_BLOCK_FILE self deposit_contract_deploy_block ) ; if let Some ( boot_enr ) = & self . boot_enr { write_to_yaml_file ! ( BOOT_ENR_FILE boot_enr ) ; } if let Some ( yaml_config ) = & self . yaml_config { write_to_yaml_file ! ( YAML_CONFIG_FILE yaml_config ) ; } // The genesis state is a special case because it uses SSZ, not YAML. if let Some ( genesis_state_bytes ) = & self . genesis_state_bytes { let file = base_dir . join ( GENESIS_STATE_FILE ) ; File :: create ( & file ) . map_err ( | e | format ! ( " " file e ) ) . and_then ( | mut file | { file . write_all ( genesis_state_bytes ) . map_err ( | e | format ! ( " " file e ) ) } ) ? ; } Ok ( ( ) ) }
Write the files to the directory, even if the directory already exists.
Write the files to the directory even if the directory already exists .
&self
base_dir
PathBuf