ethstore: retry deduplication of wallet file names until success (#8910)

This commit is contained in:
André Silva 2018-06-20 10:30:41 +01:00 committed by Wei Tang
parent 08e46432c5
commit cf5ae81ced

View File

@ -182,9 +182,22 @@ impl<T> DiskDirectory<T> where T: KeyFileManager {
// check for duplicate filename and append random suffix // check for duplicate filename and append random suffix
if dedup && keyfile_path.exists() { if dedup && keyfile_path.exists() {
const MAX_RETRIES: usize = 500;
let mut retries = 0;
let mut deduped_filename = filename.clone();
while keyfile_path.exists() {
if retries >= MAX_RETRIES {
return Err(Error::Custom(format!("Exceeded maximum retries when deduplicating account filename.")));
}
let suffix = ::random::random_string(4); let suffix = ::random::random_string(4);
filename.push_str(&format!("-{}", suffix)); deduped_filename = format!("{}-{}", filename, suffix);
keyfile_path.set_file_name(&filename); keyfile_path.set_file_name(&deduped_filename);
retries += 1;
}
filename = deduped_filename;
} }
// update account filename // update account filename