Skip to content

Commit 90f0751

Browse files
committed
wal.c: do not ignore the result code of xCb in walCheckpoint
libsql exposes a WAL checkpoint callback that is called once for each frame and right when checkpointing is about to finish. before this change, the result code returned by the checkpoint callback was ignored on the 'finish' invocation, which resulted in the checkpoint completing successfully despite the callback returning an error. this commit propagates the callback's error code and thus prevents the wal_checkpoint() routine from returning SQLITE_OK in cases where the callback failed.
1 parent 701a8cf commit 90f0751

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

libsql-ffi/bundled/src/sqlite3.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67644,9 +67644,11 @@ static int walCheckpoint(
6764467644
if (xCb) {
6764567645
rc = (xCb)(pCbData, mxSafeFrame, NULL, 0, 0, 0);
6764667646
}
67647-
i64 szDb = pWal->hdr.nPage*(i64)szPage;
67648-
testcase( IS_BIG_INT(szDb) );
67649-
rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
67647+
if( rc==SQLITE_OK ){
67648+
i64 szDb = pWal->hdr.nPage*(i64)szPage;
67649+
testcase( IS_BIG_INT(szDb) );
67650+
rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
67651+
}
6765067652
if( rc==SQLITE_OK ){
6765167653
rc = sqlite3OsSync(pWal->pDbFd, CKPT_SYNC_FLAGS(sync_flags));
6765267654
}

libsql-sqlite3/src/wal.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,9 +2134,11 @@ static int walCheckpoint(
21342134
if (xCb) {
21352135
rc = (xCb)(pCbData, mxSafeFrame, NULL, 0, 0, 0);
21362136
}
2137-
i64 szDb = pWal->hdr.nPage*(i64)szPage;
2138-
testcase( IS_BIG_INT(szDb) );
2139-
rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
2137+
if( rc==SQLITE_OK ){
2138+
i64 szDb = pWal->hdr.nPage*(i64)szPage;
2139+
testcase( IS_BIG_INT(szDb) );
2140+
rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
2141+
}
21402142
if( rc==SQLITE_OK ){
21412143
rc = sqlite3OsSync(pWal->pDbFd, CKPT_SYNC_FLAGS(sync_flags));
21422144
}

0 commit comments

Comments
 (0)