backend_firefox: improve bookmark storage init

- Check schema version when initializing database.
- Minor refactor for db_check().
This commit is contained in:
CismonX 2025-02-09 23:49:21 +08:00
parent df29392008
commit 4f8b15fd80
No known key found for this signature in database
GPG key ID: 3094873E29A482FB
2 changed files with 18 additions and 3 deletions

View file

@ -2728,6 +2728,22 @@ store_init (
) {
int status = -EIO;
int64_t user_version;
if (1 != db_exec(db, SQL_PRAGMA("user_version"), NULL, &user_version)) {
return status;
}
// The oldest schema version supported by modern Firefox is 52,
// which was used in Firefox 62-68. Fortunately, it has not changed
// in a way that makes it incompatible with this backend.
//
// Schema version 78 is the latest version, used since Firefox 132.
// Bump this version whenever a new schema version is available
// (after ensuring that no incompatible changes are made).
if (user_version < 52 || user_version > 78) {
log_printf("unsupported schema version %" PRIi64, user_version);
return status;
}
char const *sql = "SELECT `id` FROM `moz_bookmarks` WHERE `guid` = ?";
sqlite3_stmt *stmt = db_prepare(db, sql, strlen(sql), false);
if (unlikely(stmt == NULL)) {

View file

@ -114,10 +114,9 @@ db_check (
int status = 0;
ssize_t nrows = db_query(stmt, NULL, 0, false, db_check_cb, &status);
if (nrows < 0) {
return nrows;
if (nrows != 1) {
return -1;
}
xassert(nrows == 1);
return status;
}