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

Commit cf5ae81

Browse files
andresilvasorpaas
authored andcommitted
ethstore: retry deduplication of wallet file names until success (#8910)
1 parent 08e4643 commit cf5ae81

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

ethstore/src/accounts_dir/disk.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,22 @@ impl<T> DiskDirectory<T> where T: KeyFileManager {
182182

183183
// check for duplicate filename and append random suffix
184184
if dedup && keyfile_path.exists() {
185-
let suffix = ::random::random_string(4);
186-
filename.push_str(&format!("-{}", suffix));
187-
keyfile_path.set_file_name(&filename);
185+
const MAX_RETRIES: usize = 500;
186+
let mut retries = 0;
187+
let mut deduped_filename = filename.clone();
188+
189+
while keyfile_path.exists() {
190+
if retries >= MAX_RETRIES {
191+
return Err(Error::Custom(format!("Exceeded maximum retries when deduplicating account filename.")));
192+
}
193+
194+
let suffix = ::random::random_string(4);
195+
deduped_filename = format!("{}-{}", filename, suffix);
196+
keyfile_path.set_file_name(&deduped_filename);
197+
retries += 1;
198+
}
199+
200+
filename = deduped_filename;
188201
}
189202

190203
// update account filename

0 commit comments

Comments
 (0)