Skip to content

Commit

Permalink
chore: add fs-util::open (paradigmxyz#12911)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Nov 27, 2024
1 parent 26bfe7c commit f9ad3f8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

5 changes: 2 additions & 3 deletions crates/cli/commands/src/init_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use reth_provider::{
BlockNumReader, DatabaseProviderFactory, StaticFileProviderFactory, StaticFileWriter,
};

use std::{fs::File, io::BufReader, path::PathBuf, str::FromStr};
use std::{io::BufReader, path::PathBuf, str::FromStr};
use tracing::info;

pub mod without_evm;
Expand Down Expand Up @@ -115,8 +115,7 @@ impl<C: ChainSpecParser<ChainSpec: EthChainSpec + EthereumHardforks>> InitStateC

info!(target: "reth::cli", "Initiating state dump");

let file = File::open(self.state)?;
let reader = BufReader::new(file);
let reader = BufReader::new(reth_fs_util::open(self.state)?);

let hash = init_from_state_dump(reader, &provider_rw, config.stages.etl)?;

Expand Down
6 changes: 6 additions & 0 deletions crates/fs-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ impl FsPathError {
}
}

/// Wrapper for [`File::open`].
pub fn open(path: impl AsRef<Path>) -> Result<File> {
let path = path.as_ref();
File::open(path).map_err(|err| FsPathError::open(err, path))
}

/// Wrapper for `std::fs::read_to_string`
pub fn read_to_string(path: impl AsRef<Path>) -> Result<String> {
let path = path.as_ref();
Expand Down
1 change: 1 addition & 0 deletions crates/optimism/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ reth-execution-types.workspace = true
reth-node-core.workspace = true
reth-optimism-node.workspace = true
reth-primitives.workspace = true
reth-fs-util.workspace = true

# so jemalloc metrics can be included
reth-node-metrics.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions crates/optimism/cli/src/commands/init_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use reth_provider::{
BlockNumReader, ChainSpecProvider, DatabaseProviderFactory, StaticFileProviderFactory,
StaticFileWriter,
};
use std::{fs::File, io::BufReader};
use std::io::BufReader;
use tracing::info;

/// Initializes the database with the genesis block.
Expand Down Expand Up @@ -70,7 +70,7 @@ impl<C: ChainSpecParser<ChainSpec = OpChainSpec>> InitStateCommandOp<C> {

info!(target: "reth::cli", "Initiating state dump");

let reader = BufReader::new(File::open(self.init_state.state)?);
let reader = BufReader::new(reth_fs_util::open(self.init_state.state)?);
let hash = init_from_state_dump(reader, &provider_rw, config.stages.etl)?;

provider_rw.commit()?;
Expand Down

0 comments on commit f9ad3f8

Please sign in to comment.