fix(cli): never treat internal cache stores as project indexes - #2405
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 yourconfig setvalues and the cross-repo store;This PR takes the rule
pass_cross_repo.calready applied and moves it into one shared predicate (cbm_is_project_index_db/cbm_is_internal_cache_dbinfoundation/str_util). Every cache-dir.dbscan in the CLI now uses it. The check compares exact filenames, so a project whose name starts with_or containsconfigstill counts as an index.Before/after on a real isolated cache (one indexed repo,
config set auto_index true,_cross_repo.dbpresent):config get auto_indexreturnsfalse;config get auto_indexreturnstrue.Test:
cli_index_enumeration_skips_internal_cache_dbsfails on main, passes with the fix, and fails again when the fix is reverted. The cli (323) and cross_repo (8) suites pass, andmake -f Makefile.cbm lint-ciis 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-indexesnever touches your settings.