use crate::ffi;
use crate::ops::*;
use crate::{DB, Error};
use std::ffi::CString;
use std::marker::PhantomData;
use std::path::Path;
const LOG_SIZE_FOR_FLUSH: u64 = 0_u64;
pub struct Checkpoint<'db> {
pub(crate) inner: *mut ffi::rocksdb_checkpoint_t,
pub(crate) _db: PhantomData<&'db ()>,
}
impl<'db> Checkpoint<'db> {
pub fn new(db: &'db DB) -> Result<Checkpoint<'db>, Error> {
db.create_checkpoint_object()
}
pub fn create_checkpoint<P: AsRef<Path>>(&self, path: P) -> Result<(), Error> {
let path = path.as_ref();
let cpath = match CString::new(path.to_string_lossy().as_bytes()) {
Ok(c) => c,
Err(_) => {
return Err(Error::new(
"Failed to convert path to CString when creating DB checkpoint".to_owned(),
));
}
};
unsafe {
ffi_try!(ffi::rocksdb_checkpoint_create(
self.inner,
cpath.as_ptr(),
LOG_SIZE_FOR_FLUSH,
));
Ok(())
}
}
}
impl Drop for Checkpoint<'_> {
fn drop(&mut self) {
unsafe {
ffi::rocksdb_checkpoint_object_destroy(self.inner);
}
}
}