mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-06-30 06:24:29 +02:00
32 lines
484 B
Rust
32 lines
484 B
Rust
use std::sync::Arc;
|
|
|
|
use super::KeyValueDatabaseEngine;
|
|
|
|
pub struct Cork {
|
|
db: Arc<dyn KeyValueDatabaseEngine>,
|
|
flush: bool,
|
|
sync: bool,
|
|
}
|
|
|
|
impl Cork {
|
|
pub fn new(db: &Arc<dyn KeyValueDatabaseEngine>, flush: bool, sync: bool) -> Self {
|
|
db.cork().unwrap();
|
|
Cork {
|
|
db: db.clone(),
|
|
flush,
|
|
sync,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Drop for Cork {
|
|
fn drop(&mut self) {
|
|
self.db.uncork().ok();
|
|
if self.flush {
|
|
self.db.flush().ok();
|
|
}
|
|
if self.sync {
|
|
self.db.sync().ok();
|
|
}
|
|
}
|
|
}
|