Merge pull request #2405 from DeusData/fix/internal-db-enumeration

fix(cli): never treat internal cache stores as project indexes
This commit is contained in:
Martin Vogel
2026-09-30 22:21:11 +02:00
committed by GitHub
6 changed files with 114 additions and 18 deletions
+6 -9
View File
@@ -23,6 +23,7 @@
#include "foundation/constants.h"
#include "foundation/log.h"
#include "foundation/sha256.h"
#include "foundation/str_util.h"
#include "cli/client_adapter.h"
#include "mcp/mcp.h" // cbm_mcp_tool_input_schema — CLI flag parser + per-tool --help
#include "mcp/index_supervisor.h"
@@ -62,7 +63,6 @@ enum {
SQL_PARAM_1 = 1, /* sqlite3_bind parameter index 1 */
SQL_PARAM_2 = 2,
SEMVER_PARTS = 3, /* major.minor.patch */
DB_EXT_LEN = 3, /* strlen(".db") */
MIN_ARGC_CMD = 3,
/* minimum argc for subcommand with arg */ /* sqlite3_bind parameter index 2 */ /* 10 MB cap
factor */
@@ -7207,8 +7207,7 @@ int cbm_list_indexes(const char *home_dir) {
int count = 0;
cbm_dirent_t *ent;
while ((ent = cbm_readdir(d)) != NULL) {
size_t len = strlen(ent->name);
if (len > DB_EXT_LEN && strcmp(ent->name + len - DB_EXT_LEN, ".db") == 0) {
if (cbm_is_project_index_db(ent->name)) {
printf(" %s/%s\n", cache_dir, ent->name);
count++;
}
@@ -7231,8 +7230,7 @@ int cbm_remove_indexes(const char *home_dir) {
int count = 0;
cbm_dirent_t *ent;
while ((ent = cbm_readdir(d)) != NULL) {
size_t len = strlen(ent->name);
if (len > DB_EXT_LEN && strcmp(ent->name + len - DB_EXT_LEN, ".db") == 0) {
if (cbm_is_project_index_db(ent->name)) {
char path[CLI_BUF_1K];
snprintf(path, sizeof(path), "%s/%s", cache_dir, ent->name);
/* Also remove .db.tmp if present */
@@ -7268,7 +7266,7 @@ cbm_config_t *cbm_config_open(const char *cache_dir) {
}
char dbpath[CLI_BUF_1K];
snprintf(dbpath, sizeof(dbpath), "%s/_config.db", cache_dir);
snprintf(dbpath, sizeof(dbpath), "%s/" CBM_CONFIG_DB_FILENAME, cache_dir);
/* Ensure directory exists */
mkdirp(cache_dir, DIR_PERMS);
@@ -10437,7 +10435,7 @@ static int cbm_install_agent_configs_with_previous(const char *home, const char
return result;
}
/* Count .db files in the cache directory. */
/* Count project index .db files in the cache directory (internal stores excluded). */
static int count_db_indexes(const char *home) {
const char *cache_dir = get_cache_dir(home);
if (!cache_dir) {
@@ -10450,8 +10448,7 @@ static int count_db_indexes(const char *home) {
int count = 0;
cbm_dirent_t *ent;
while ((ent = cbm_readdir(d)) != NULL) {
size_t len = strlen(ent->name);
if (len > DB_EXT_LEN && strcmp(ent->name + len - DB_EXT_LEN, ".db") == 0) {
if (cbm_is_project_index_db(ent->name)) {
count++;
}
}