ethstore: retry deduplication of wallet file names until success (#8910)
This commit is contained in:
parent
08e46432c5
commit
cf5ae81ced
@ -182,9 +182,22 @@ impl<T> DiskDirectory<T> where T: KeyFileManager {
|
||||
|
||||
// check for duplicate filename and append random suffix
|
||||
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);
|
||||
filename.push_str(&format!("-{}", suffix));
|
||||
keyfile_path.set_file_name(&filename);
|
||||
deduped_filename = format!("{}-{}", filename, suffix);
|
||||
keyfile_path.set_file_name(&deduped_filename);
|
||||
retries += 1;
|
||||
}
|
||||
|
||||
filename = deduped_filename;
|
||||
}
|
||||
|
||||
// update account filename
|
||||
|
Loading…
Reference in New Issue
Block a user