feat(ck-core): add CK_INDEX_DIR to relocate index directories - #165
Merged
Conversation
…the source tree By default ck stores each search root's index in an in-tree `.ck/` directory. That is convenient but not always wanted: it clutters repositories, can't be shared between multiple checkouts of the same tree, and is awkward to cache in CI. When `CK_INDEX_DIR` is set, the index for a search root instead lives at `$CK_INDEX_DIR/<basename>-<hash>`, where `<hash>` is the first 8 hex characters of the blake3 hash of the root's absolute path so two roots that share a basename never collide. Unset preserves the existing `<root>/.ck` behavior exactly. Introduce two documented helpers in ck-core: `index_dir(root)` returns the index/sidecar directory for a search root and `index_exists(root)` reports whether it exists. Both the relocation base and the root are absolutized, so the returned path is independent of the current directory (a relative CK_INDEX_DIR is anchored at the launch directory rather than resolved per-process). The environment variable is read on every call (an empty value is treated as unset) and never panics. Every call site that computed `<root>/.ck` — across ck-index, ck-engine, ck-cli, ck-tui, and ck-core's own sidecar and PDF content-cache paths, including the walk-ups that probe for a nearby index — now routes through these helpers. The `.ck` default-exclude pattern and sidecar file extensions are unchanged. Because an 8-hex hash can in principle collide, a relocated index directory records its search root in a `root_path` marker file; indexing refuses to write into a directory claimed by a different root, and searches refuse to serve one, surfacing a clear error instead of silently returning another root's results. Tests covering env-dependent paths are serialized with serial_test (already used elsewhere in ck) and clear the variable so they exercise default behavior deterministically. Documented under "Index Storage" in the README.
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.
Summary
By default ck stores each search root's index in an in-tree
.ck/directory. This adds an opt-inCK_INDEX_DIRenvironment variable: when set, a search root R is indexed under$CK_INDEX_DIR/<basename(R)>-<hash>(first 8 hex chars of the blake3 hash of R's canonical absolute path, so same-basename roots get distinct directories). When unset, behavior is byte-identical to today.Motivation
.ck/directories.Implementation
Two documented helpers in ck-core (
index_dir,index_exists) plus anINDEX_DIR_ENVconst; every<root>/.ckcomputation routes through them, including the walk-up probes, the tantivy meta file, and the index write lock, so all index state co-locates. The env value is absolutized before use so a relative value can't split the lock from the index. Each relocated index directory carries aroot_pathmarker naming the root it was built for; indexing and search refuse a directory claimed by a different root, surfacing a clear error rather than silently mixing two roots' data in the (unlikely) event of a hash collision.Notes / limitations
ck --cleanfirst, or remove them manually). In-tree.ckdisappears with the repo; a relocated index does not.Tests
ck-core units for unset/set/empty/collision/absolutization/marker; env-touching tests serialized with
serial_test(the crate the test suite already uses);cargo test --workspacegreen both with and withoutCK_INDEX_DIRset; fmt and clippy clean. README documents the variable under "Index Storage".