Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean the header folder in sandbox #2716

Merged
merged 2 commits into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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