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

feat(nippy-jar): use reth_primitives::fs to preserve path in errors #6272

Merged
merged 2 commits into from
Jan 29, 2024
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
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.

2 changes: 2 additions & 0 deletions crates/storage/nippy-jar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ workspace = true
name = "reth_nippy_jar"

[dependencies]
# reth
reth-primitives.workspace = true

# filter
ph = "0.8.0"
Expand Down
2 changes: 2 additions & 0 deletions crates/storage/nippy-jar/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub enum NippyJarError {
Internal(#[from] Box<dyn std::error::Error + Send + Sync>),
#[error(transparent)]
Disconnect(#[from] std::io::Error),
#[error(transparent)]
FileSystem(#[from] reth_primitives::fs::FsPathError),
#[error("{0}")]
Custom(String),
#[error(transparent)]
Expand Down
10 changes: 7 additions & 3 deletions crates/storage/nippy-jar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ impl<H: NippyJarHeader> NippyJar<H> {
/// **The user must ensure the header type matches the one used during the jar's creation.**
pub fn load(path: &Path) -> Result<Self, NippyJarError> {
// Read [`Self`] located at the data file.
let config_file = File::open(path.with_extension(CONFIG_FILE_EXTENSION))?;
let config_path = path.with_extension(CONFIG_FILE_EXTENSION);
let config_file = File::open(&config_path)
.map_err(|err| reth_primitives::fs::FsPathError::open(err, config_path))?;

let mut obj: Self = bincode::deserialize_from(&config_file)?;
obj.path = path.to_path_buf();
Expand All @@ -243,7 +245,9 @@ impl<H: NippyJarHeader> NippyJar<H> {
/// Loads filters into memory
pub fn load_filters(mut self) -> Result<Self, NippyJarError> {
// Read the offsets lists located at the index file.
let mut offsets_file = File::open(self.index_path())?;
let offsets_path = self.index_path();
let mut offsets_file = File::open(&offsets_path)
.map_err(|err| reth_primitives::fs::FsPathError::open(err, offsets_path))?;

self.offsets_index = PrefixSummedEliasFano::deserialize_from(&mut offsets_file)?;
self.phf = bincode::deserialize_from(&mut offsets_file)?;
Expand Down Expand Up @@ -279,7 +283,7 @@ impl<H: NippyJarHeader> NippyJar<H> {
[self.data_path().into(), self.index_path(), self.offsets_path(), self.config_path()]
{
if path.exists() {
std::fs::remove_file(path)?;
reth_primitives::fs::remove_file(path)?;
}
}

Expand Down
Loading