From b8872e36e92c4fa02def13185c5a06641eabd0ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Mon, 12 Feb 2018 18:03:37 +0100 Subject: [PATCH] Flush keyfiles. Resolves #7632 (#7868) --- ethstore/src/accounts_dir/disk.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ethstore/src/accounts_dir/disk.rs b/ethstore/src/accounts_dir/disk.rs index d164cb6bbc2..46a0ecf399b 100755 --- a/ethstore/src/accounts_dir/disk.rs +++ b/ethstore/src/accounts_dir/disk.rs @@ -15,6 +15,7 @@ // along with Parity. If not, see . use std::{fs, io}; +use std::io::Write; use std::path::{PathBuf, Path}; use std::collections::HashMap; use time; @@ -166,17 +167,17 @@ impl DiskDirectory where T: KeyFileManager { // save the file let mut file = fs::File::create(&keyfile_path)?; - if let Err(err) = self.key_manager.write(original_account, &mut file).map_err(|e| Error::Custom(format!("{:?}", e))) { - drop(file); - fs::remove_file(keyfile_path).expect("Expected to remove recently created file"); - return Err(err); - } + + // Write key content + self.key_manager.write(original_account, &mut file).map_err(|e| Error::Custom(format!("{:?}", e)))?; + + file.flush()?; if let Err(_) = restrict_permissions_to_owner(keyfile_path.as_path()) { - drop(file); - fs::remove_file(keyfile_path).expect("Expected to remove recently created file"); return Err(Error::Io(io::Error::last_os_error())); } + + file.sync_all()?; } Ok(account)