chore: add fs-util::open (#12911)

This commit is contained in:
Matthias Seitz
2024-11-27 17:22:23 +01:00
committed by GitHub
parent 26bfe7c037
commit f9ad3f8cca
5 changed files with 12 additions and 5 deletions

1
Cargo.lock generated
View File

@ -8237,6 +8237,7 @@ dependencies = [
"reth-downloaders",
"reth-errors",
"reth-execution-types",
"reth-fs-util",
"reth-network-p2p",
"reth-node-builder",
"reth-node-core",

View File

@ -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;
@ -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)?;

View File

@ -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();

View File

@ -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

View File

@ -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.
@ -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()?;