| 461 | static bool ui_log_import_legacy(sqlite3 *db, const char *cache); |
| 462 | |
| 463 | static sqlite3 *activity_db_locked(void) { |
| 464 | char path[CBM_SZ_2K]; |
| 465 | const char *cache = cbm_resolve_cache_dir(); |
| 466 | int n = snprintf(path, sizeof(path), "%s/activity.db", cache ? cache : ""); |
| 467 | if (!cache || !*cache || n < 0 || (size_t)n >= sizeof(path)) |
| 468 | return NULL; |
| 469 | if (strcmp(path, g_activity_path)) { |
| 470 | sqlite3_close(g_activity_db); |
| 471 | g_activity_db = NULL; |
| 472 | snprintf(g_activity_path, sizeof(g_activity_path), "%s", path); |
| 473 | } |
| 474 | if (!g_activity_db) { |
| 475 | cbm_mkdir_p(cache, 0700); |
| 476 | g_activity_db = cbm_activity_open(path); |
| 477 | if (g_activity_db && !ui_log_import_legacy(g_activity_db, cache)) { |
| 478 | sqlite3_close(g_activity_db); |
| 479 | g_activity_db = NULL; |
| 480 | } |
| 481 | } |
| 482 | return g_activity_db; |
| 483 | } |
| 484 | |
| 485 | /* Called from a log hook — appends a line to the ring buffer (thread-safe) */ |
| 486 | static void ui_log_append_record(const char *line, const char *record) { |
no test coverage detected