Skip to content

Commit

Permalink
Merge pull request #62 from iqlusioninc/replace-atomicwrites-with-tem…
Browse files Browse the repository at this point in the history
…pfile

Replace `atomicwrites` dependency with `tempfile`
  • Loading branch information
tony-iqlusion authored Jun 8, 2020
2 parents ae63a8c + fbede60 commit c000179
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 70 deletions.
69 changes: 3 additions & 66 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ edition = "2018"

[dependencies]
abscissa_core = "0.5"
atomicwrites = "0.2"
bytes = "0.5"
chacha20poly1305 = "0.4"
chrono = "0.4"
Expand All @@ -35,6 +34,7 @@ signatory-secp256k1 = "0.19"
signatory-ledger-tm = { version = "0.19", optional = true }
subtle = "2"
subtle-encoding = { version = "0.5", features = ["bech32-preview"] }
tempfile = "3"
tendermint = "0.13"
thiserror = "1"
wait-timeout = "0.2"
Expand Down
11 changes: 8 additions & 3 deletions src/chain/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ use crate::{
error::{Error, ErrorKind::*},
prelude::*,
};
use atomicwrites::{AtomicFile, OverwriteBehavior};
use std::{
fs,
io::{self, prelude::*},
path::{Path, PathBuf},
};
use tempfile::NamedTempFile;
use tendermint::consensus;

/// State tracking for double signing prevention
Expand Down Expand Up @@ -187,8 +187,13 @@ impl State {

let json = serde_json::to_string(&self.consensus_state)?;

AtomicFile::new(&self.state_file_path, OverwriteBehavior::AllowOverwrite)
.write(|f| f.write_all(json.as_bytes()))?;
let state_file_dir = self.state_file_path.parent().unwrap_or_else(|| {
panic!("state file cannot be root directory");
});

let mut state_file = NamedTempFile::new_in(state_file_dir)?;
state_file.write_all(json.as_bytes())?;
state_file.persist(&self.state_file_path)?;

debug!(
"successfully wrote new consensus state to {}",
Expand Down

0 comments on commit c000179

Please sign in to comment.