Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
ethstore: retry deduplication of wallet file names until success (#8910)
Browse files Browse the repository at this point in the history
  • Loading branch information
andresilva authored and sorpaas committed Jun 20, 2018
1 parent 08e4643 commit cf5ae81
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions ethstore/src/accounts_dir/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,22 @@ impl<T> DiskDirectory<T> where T: KeyFileManager {

// check for duplicate filename and append random suffix
if dedup && keyfile_path.exists() {
let suffix = ::random::random_string(4);
filename.push_str(&format!("-{}", suffix));
keyfile_path.set_file_name(&filename);
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);
deduped_filename = format!("{}-{}", filename, suffix);
keyfile_path.set_file_name(&deduped_filename);
retries += 1;
}

filename = deduped_filename;
}

// update account filename
Expand Down

0 comments on commit cf5ae81

Please sign in to comment.