global: snapshot

This commit is contained in:
nym21
2025-03-11 17:55:14 +01:00
parent b9e679a514
commit b4fbcf6bee
5 changed files with 26 additions and 35 deletions

View File

@@ -2,6 +2,7 @@ use core::error;
use std::{
cmp::Ordering,
fmt::Debug,
io,
ops::{Add, Deref, DerefMut, Sub},
path::{Path, PathBuf},
};
@@ -37,6 +38,16 @@ where
index.try_into().map_err(|_| Error::FailedKeyTryIntoUsize)
}
fn safe_truncate_if_needed(&mut self, index: I, exit: &Exit) -> Result<()> {
if exit.triggered() {
return Ok(());
}
exit.block();
self.truncate_if_needed(index)?;
exit.release();
Ok(())
}
#[inline]
fn push_and_flush_if_needed(&mut self, index: I, value: T, exit: &Exit) -> Result<()> {
match self.len().cmp(&Self::i_to_usize(index)?) {
@@ -58,6 +69,16 @@ where
}
}
pub fn safe_flush(&mut self, exit: &Exit) -> io::Result<()> {
if exit.triggered() {
return Ok(());
}
exit.block();
self.flush()?;
exit.release();
Ok(())
}
#[inline]
fn path_computed_version(&self) -> PathBuf {
self.path().join("computed_version")