Skip to content

Commit 4aa5460

Browse files
committed
pass proper checkpoint mode and handle checkpoint result
1 parent fd990f7 commit 4aa5460

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

libsql/src/local/connection.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,22 @@ impl Connection {
495495
}
496496

497497
pub(crate) fn wal_checkpoint(&self, truncate: bool) -> Result<()> {
498-
let rc = unsafe { libsql_sys::ffi::sqlite3_wal_checkpoint_v2(self.handle(), std::ptr::null(), truncate as i32, std::ptr::null_mut(), std::ptr::null_mut()) };
498+
let mut pn_log = 0i32;
499+
let mut pn_ckpt = 0i32;
500+
let checkpoint_mode = if truncate {
501+
libsql_sys::ffi::SQLITE_CHECKPOINT_TRUNCATE
502+
} else {
503+
0
504+
};
505+
let rc = unsafe {
506+
libsql_sys::ffi::sqlite3_wal_checkpoint_v2(
507+
self.handle(),
508+
std::ptr::null(),
509+
checkpoint_mode,
510+
&mut pn_log,
511+
&mut pn_ckpt,
512+
)
513+
};
499514
if rc != 0 {
500515
let err_msg = unsafe { libsql_sys::ffi::sqlite3_errmsg(self.handle()) };
501516
let err_msg = unsafe { std::ffi::CStr::from_ptr(err_msg) };
@@ -505,6 +520,12 @@ impl Connection {
505520
format!("Failed to checkpoint WAL: {}", err_msg),
506521
));
507522
}
523+
if truncate && (pn_log != 0 || pn_ckpt != 0) {
524+
return Err(crate::errors::Error::SqliteFailure(
525+
libsql_sys::ffi::SQLITE_ERROR,
526+
"unable to truncate WAL".to_string(),
527+
));
528+
}
508529
Ok(())
509530
}
510531

0 commit comments

Comments
 (0)