Skip to content

Commit

Permalink
clean the header folder in sandbox (#2716)
Browse files Browse the repository at this point in the history
* forgot to clean the header folder in sandbox in #2685
  • Loading branch information
garyyu authored and ignopeverell committed Mar 29, 2019
1 parent cea1390 commit 340070f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,9 @@ impl Chain {

/// Clean the temporary sandbox folder
pub fn clean_txhashset_sandbox(&self) {
txhashset::clean_txhashset_folder(&env::temp_dir());
let sandbox_dir = env::temp_dir();
txhashset::clean_txhashset_folder(&sandbox_dir);
txhashset::clean_header_folder(&sandbox_dir);
}

/// Writes a reading view on a txhashset state that's been provided to us.
Expand All @@ -879,6 +881,7 @@ impl Chain {
// Write txhashset to sandbox (in the os temporary directory)
let sandbox_dir = env::temp_dir();
txhashset::clean_txhashset_folder(&sandbox_dir);
txhashset::clean_header_folder(&sandbox_dir);
txhashset::zip_write(sandbox_dir.clone(), txhashset_data.try_clone()?, &header)?;

let mut txhashset = txhashset::TxHashSet::open(
Expand Down Expand Up @@ -949,7 +952,7 @@ impl Chain {

// Move sandbox to overwrite
txhashset.release_backend_files();
txhashset::txhashset_replace(sandbox_dir, PathBuf::from(self.db_root.clone()))?;
txhashset::txhashset_replace(sandbox_dir.clone(), PathBuf::from(self.db_root.clone()))?;

// Re-open on db root dir
txhashset = txhashset::TxHashSet::open(
Expand All @@ -959,6 +962,7 @@ impl Chain {
)?;

self.rebuild_header_mmr(&Tip::from_header(&header), &mut txhashset)?;
txhashset::clean_header_folder(&sandbox_dir);

// Replace the chain txhashset with the newly built one.
*txhashset_ref = txhashset;
Expand Down
10 changes: 10 additions & 0 deletions chain/src/txhashset/txhashset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,16 @@ pub fn clean_txhashset_folder(root_dir: &PathBuf) {
}
}

/// Clean the header folder
pub fn clean_header_folder(root_dir: &PathBuf) {
let header_path = root_dir.clone().join(HEADERHASHSET_SUBDIR);
if header_path.exists() {
if let Err(e) = fs::remove_dir_all(header_path.clone()) {
warn!("clean_header_folder: fail on {:?}. err: {}", header_path, e);
}
}
}

fn expected_file(path: &Path) -> bool {
use lazy_static::lazy_static;
use regex::Regex;
Expand Down

0 comments on commit 340070f

Please sign in to comment.