Skip to content

Commit

Permalink
Makes ValueTable::init_with_entry cleanly abort on error (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tpt authored Sep 21, 2022
1 parent 04f40bd commit 72dd091
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,13 @@ impl TableFile {
}
Ok(())
}

pub fn remove(&self) -> Result<()> {
let mut file = self.file.write();
if let Some(file) = file.take() {
drop(file);
try_io!(std::fs::remove_file(&self.path));
}
Ok(())
}
}
9 changes: 9 additions & 0 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,15 @@ impl ValueTable {
}

pub fn init_with_entry(&self, entry: &[u8]) -> Result<()> {
if let Err(e) = self.do_init_with_entry(entry) {
log::error!(target: "parity-db", "Failure to initialize file {}", self.file.path.display());
let _ = self.file.remove(); // We ignore error here
return Err(e)
}
Ok(())
}

fn do_init_with_entry(&self, entry: &[u8]) -> Result<()> {
self.file.grow(self.entry_size)?;

let empty_overlays = parking_lot::RwLock::new(Default::default());
Expand Down

0 comments on commit 72dd091

Please sign in to comment.