Move genesis/snapshot archive download into Rust (#5515)
This commit is contained in:
@ -102,9 +102,9 @@ extern crate solana_metrics;
|
||||
#[macro_use]
|
||||
extern crate matches;
|
||||
|
||||
extern crate bzip2;
|
||||
extern crate crossbeam_channel;
|
||||
extern crate dir_diff;
|
||||
extern crate flate2;
|
||||
extern crate fs_extra;
|
||||
extern crate tar;
|
||||
extern crate tempfile;
|
||||
|
@ -70,8 +70,8 @@ impl RequestMiddleware for RpcRequestMiddleware {
|
||||
fn on_request(&self, request: hyper::Request<hyper::Body>) -> RequestMiddlewareAction {
|
||||
trace!("request uri: {}", request.uri());
|
||||
match request.uri().path() {
|
||||
"/snapshot.tgz" => self.get("snapshot.tgz"),
|
||||
"/genesis.tgz" => self.get("genesis.tgz"),
|
||||
"/snapshot.tar.bz2" => self.get("snapshot.tar.bz2"),
|
||||
"/genesis.tar.bz2" => self.get("genesis.tar.bz2"),
|
||||
_ => RequestMiddlewareAction::Proceed {
|
||||
should_continue_on_invalid_cors: false,
|
||||
request,
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::result::{Error, Result};
|
||||
use crate::service::Service;
|
||||
use flate2::write::GzEncoder;
|
||||
use flate2::Compression;
|
||||
use bzip2::write::BzEncoder;
|
||||
use solana_runtime::accounts_db::AccountStorageEntry;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
@ -77,11 +76,11 @@ impl SnapshotPackagerService {
|
||||
// Create the tar builder
|
||||
let tar_gz = tempfile::Builder::new()
|
||||
.prefix("new_state")
|
||||
.suffix(".tgz")
|
||||
.suffix(".tar.bz2")
|
||||
.tempfile_in(tar_dir)?;
|
||||
|
||||
let temp_tar_path = tar_gz.path();
|
||||
let enc = GzEncoder::new(&tar_gz, Compression::default());
|
||||
let enc = BzEncoder::new(&tar_gz, bzip2::Compression::Default);
|
||||
let mut tar = tar::Builder::new(enc);
|
||||
|
||||
// Create the list of paths to compress, starting with the snapshots
|
||||
|
@ -3,7 +3,7 @@ use crate::result::{Error, Result};
|
||||
use crate::snapshot_package::SnapshotPackage;
|
||||
use crate::snapshot_package::{TAR_ACCOUNTS_DIR, TAR_SNAPSHOTS_DIR};
|
||||
use bincode::{deserialize_from, serialize_into};
|
||||
use flate2::read::GzDecoder;
|
||||
use bzip2::bufread::BzDecoder;
|
||||
use fs_extra::dir::CopyOptions;
|
||||
use solana_runtime::bank::Bank;
|
||||
use solana_runtime::status_cache::SlotDelta;
|
||||
@ -198,15 +198,15 @@ pub fn bank_from_archive<P: AsRef<Path>>(
|
||||
}
|
||||
|
||||
pub fn get_snapshot_tar_path<P: AsRef<Path>>(snapshot_output_dir: P) -> PathBuf {
|
||||
snapshot_output_dir.as_ref().join("snapshot.tgz")
|
||||
snapshot_output_dir.as_ref().join("snapshot.tar.bz2")
|
||||
}
|
||||
|
||||
pub fn untar_snapshot_in<P: AsRef<Path>, Q: AsRef<Path>>(
|
||||
snapshot_tar: P,
|
||||
unpack_dir: Q,
|
||||
) -> Result<()> {
|
||||
let tar_gz = File::open(snapshot_tar)?;
|
||||
let tar = GzDecoder::new(tar_gz);
|
||||
let tar_bz2 = File::open(snapshot_tar)?;
|
||||
let tar = BzDecoder::new(BufReader::new(tar_bz2));
|
||||
let mut archive = Archive::new(tar);
|
||||
archive.unpack(&unpack_dir)?;
|
||||
Ok(())
|
||||
|
Reference in New Issue
Block a user