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

Commit

Permalink
Flush keyfiles. Resolves #7632 (#7868)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomusdrw committed Feb 14, 2018
1 parent 47fb19d commit b8872e3
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions ethstore/src/accounts_dir/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

use std::{fs, io};
use std::io::Write;
use std::path::{PathBuf, Path};
use std::collections::HashMap;
use time;
Expand Down Expand Up @@ -166,17 +167,17 @@ impl<T> DiskDirectory<T> 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)
Expand Down

0 comments on commit b8872e3

Please sign in to comment.