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

copying chain_cache in temp dirs, one copy per zebrad process #79

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
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
33 changes: 31 additions & 2 deletions services/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,20 @@ impl Validator for Zebrad {
}

let cache_dir = if let Some(cache) = config.chain_cache.clone() {
Self::load_chain(cache.clone(), data_dir.path().to_path_buf(), config.network);
cache
println!("creating temp dir to copy cache into");
// create temp dir to copy the cache into
let temp_dir = TempDir::new().expect("temp_dir to be created");

copy_dir_all(cache.clone(), &temp_dir.path()).expect("cache to be copied");

Self::load_chain(
temp_dir.path().to_path_buf(),
data_dir.path().to_path_buf(),
config.network,
);
let cache_dir = temp_dir.path().to_path_buf();
dbg!(&cache_dir);
cache_dir
} else {
data_dir.path().to_path_buf()
};
Expand Down Expand Up @@ -630,3 +642,20 @@ impl Drop for Zebrad {
self.stop();
}
}

use std::path::Path;
use std::{fs, io};

fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
fs::create_dir_all(&dst)?;
for entry in fs::read_dir(src)? {
let entry = entry?;
let ty = entry.file_type()?;
if ty.is_dir() {
copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?;
} else {
fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?;
}
}
Ok(())
}