Skip to content

fix(cli): never treat internal cache stores as project indexes - #2405

Merged
DeusData merged 1 commit into
mainfrom
fix/internal-db-enumeration
Sep 30, 2026
Merged

DeusData merged 1 commit into
mainfrom
fix/internal-db-enumeration

Conversation

@DeusData

Copy link
Copy Markdown
Owner

The cache directory holds two internal SQLite stores next to the project indexes: your settings (_config.db) and the cross-repo store (_cross_repo.db). The CLI's index list, count and remove helpers matched every *.db. As a result:

  • install --reset-indexes, and uninstall when you confirm index deletion, also wiped your config set values and the cross-repo store;
  • "Found N index(es)" over-counted.

This PR takes the rule pass_cross_repo.c already applied and moves it into one shared predicate (cbm_is_project_index_db / cbm_is_internal_cache_db in foundation/str_util). Every cache-dir .db scan in the CLI now uses it. The check compares exact filenames, so a project whose name starts with _ or contains config still counts as an index.

Before/after on a real isolated cache (one indexed repo, config set auto_index true, _cross_repo.db present):

  • before: Found 3 / Removed 3, the cache emptied, and config get auto_index returns false;
  • after: Found 1 / Removed 1, both internal stores kept, and config get auto_index returns true.

Test: cli_index_enumeration_skips_internal_cache_dbs fails on main, passes with the fix, and fails again when the fix is reverted. The cli (323) and cross_repo (8) suites pass, and make -f Makefile.cbm lint-ci is clean.

This PR combines cleanly with the "uninstall keeps indexes unless --delete-indexes" change (#2200) and with #2353. With all of them in, even --delete-indexes never touches your settings.

The cache directory holds two internal SQLite stores next to the project
indexes: the user's settings (_config.db) and the cross-repo store
(_cross_repo.db). cbm_list_indexes, cbm_remove_indexes and
count_db_indexes matched every "*.db" there. As a result:

- install --reset-indexes and uninstall (when index deletion is confirmed)
  deleted the user's config (every `config set` value silently reverted
  to its default) and the cross-repo store along with the indexes;
- the "Found N index(es)" listing and count over-reported by up to two.

pass_cross_repo.c already excluded both stores by exact filename, but in
its own copy of the check. Centralise the rule in foundation/str_util:
cbm_is_internal_cache_db() (exact names, so a real project whose name
starts with "_" or contains "config" is still an index) and
cbm_is_project_index_db(). Every enumeration of the cache directory's
.db files (list, count, remove, cross-repo target scan) now calls it, and
cbm_config_open() builds its path from the same CBM_CONFIG_DB_FILENAME
constant.

Proof on a real isolated cache (one indexed Go repo, `config set
auto_index true`, a _cross_repo.db present):
  before: "Found 3 index(es)", "Removed 3 index(es)", cache left empty,
          `config get auto_index` -> false
  after:  "Found 1 index(es)", "Removed 1 index(es)", _config.db and
          _cross_repo.db kept, `config get auto_index` -> true

Test: cli::cli_index_enumeration_skips_internal_cache_dbs (RED on main,
green with the fix, RED again on revert).

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
@DeusData
DeusData merged commit 48acb55 into main Sep 30, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant