Skip to content

Make --data-dir move the cache with it - #143

Merged
tamnd merged 1 commit into
mainfrom
fix-data-dir-moves-cache
Aug 12, 2026
Merged

tamnd merged 1 commit into
mainfrom
fix-data-dir-moves-cache

Conversation

@tamnd

@tamnd tamnd commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Closes #138.

cli.md says cache_dir "follows data_dir when unset" and the config file honoured that, but --data-dir did not. kit computes its default cache dir from its default data dir before any flag is parsed, so --data-dir /somewhere/fresh moved the downloads, the Parquet, and the DuckDB file, and left the cache pointing at the old tree.

That is not only untidy. It came up while measuring #137: a run aimed at an empty directory to prove a command fails without a cache came back exit 0, because it was reading the ambient cache the whole time. A flag that looks like isolation and is not gives you the wrong answer with no sign anything was wrong.

The cache dir now follows kit's resolved data dir unless somebody named it, and "named" is the same settings.value("cache_dir") lookup the config file path already used, so CCRAWL_CACHE_DIR and a cache_dir line both pin it whichever way the data dir moved.

While in there: config show reported default as the source of cache_dir and db_path even when both had moved with the data dir. That column exists to end questions about where a value came from, and default next to a moved path starts one. Both now say derived from data_dir when that is what happened, the same as raw_dir and parquet_dir.

Measured live

Before, on the same binary with the index server down:

$ ccrawl crawls latest --data-dir /tmp/emptydata; echo $?
CC-MAIN-2026-30
0

After:

$ ccrawl cache dir
/Users/apple/data/ccrawl/cache
$ ccrawl cache dir --data-dir /tmp/dd1
/tmp/dd1/cache
$ CCRAWL_CACHE_DIR=/tmp/envcache ccrawl cache dir --data-dir /tmp/dd1
/tmp/envcache

$ ccrawl crawls latest --data-dir /tmp/emptydata; echo $?
Fetch collinfo: all 6 attempts failed ... connect: connection refused.
8
$ ccrawl crawls latest; echo $?
CC-MAIN-2026-30
0

config show, before and after:

$ ccrawl config show --data-dir /tmp/dd2 -o csv
data_dir,/tmp/dd2,flag --data-dir
cache_dir,/tmp/dd2/cache,default              <- said default, was not
db_path,/tmp/dd2/ccrawl.duckdb,default        <- same

$ ccrawl config show --data-dir /tmp/dd2 -o csv
data_dir,/tmp/dd2,flag --data-dir
cache_dir,/tmp/dd2/cache,derived from data_dir
db_path,/tmp/dd2/ccrawl.duckdb,derived from data_dir

$ CCRAWL_CACHE_DIR=/tmp/envc CCRAWL_DB_PATH=/tmp/x.duckdb ccrawl config show -o csv
cache_dir,/tmp/envc,env CCRAWL_CACHE_DIR
db_path,/tmp/x.duckdb,env CCRAWL_DB_PATH

Done when

  • --data-dir moves the cache dir with it, the way the reference says it does
  • a cache dir named in the config file or the environment stays where it was put
  • config show names the data dir as the source of a path that followed it
  • the configuration page shows the sources it now prints

Checks

gofmt -l . clean, go vet ./... clean, go test ./... passing, scripts/docs-drift.sh matches the binary, scripts/coverage.sh above every floor with cli at 53.1%, golangci-lint run ./... 0 issues.

New tests: TestTheDataDirFlagMovesTheCache covers the flag moving the cache, the flag not being given, and the two ways of pinning it, and TestConfigShowSaysWhichPathsFollowTheDataDir checks the source column through the command line. Both sit below the command line for the pinning cases, because the test harness exports CCRAWL_CACHE_DIR for every run so tests cannot read each other's caches.

The reference has always said the cache dir follows the data dir when
nothing names it, and the config file honoured that, but the flag did
not. kit works out its default cache dir from its default data dir
before any flag is parsed, so a run pointed at a fresh tree with
--data-dir went on reading the old tree's cache. A command aimed at an
empty directory answered out of a cache it should not have been able to
see, which is how a measurement of an offline index server came back
green.

The cache dir now follows kit's resolved data dir unless somebody named
it, and named is the same lookup the config file path already used, so
CCRAWL_CACHE_DIR and a cache_dir line pin it whichever way the data dir
moved.

config show was reporting "default" for cache_dir and db_path even when
both had moved with the data dir, which reads as nothing touched this.
Both now say "derived from data_dir" when that is what happened, the
way raw_dir and parquet_dir already did.
@tamnd tamnd added this to the v0.10.1 milestone Aug 12, 2026
@tamnd tamnd added type: bug Something is wrong area: cli Command surface, flags, config labels Aug 12, 2026
@tamnd
tamnd merged commit 5a1f832 into main Aug 12, 2026
8 checks passed
@tamnd
tamnd deleted the fix-data-dir-moves-cache branch August 12, 2026 23:05
@github-actions github-actions Bot mentioned this pull request Aug 12, 2026
34 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli Command surface, flags, config type: bug Something is wrong

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--data-dir does not move the cache, though the reference says it does

1 participant