Skip to content

fix(bookworm): Use OS cache dir and fix multi-platform sanitize#662

Open
JeanMertz wants to merge 2 commits into
mainfrom
prr229
Open

fix(bookworm): Use OS cache dir and fix multi-platform sanitize#662
JeanMertz wants to merge 2 commits into
mainfrom
prr229

Conversation

@JeanMertz
Copy link
Copy Markdown
Collaborator

Cache downloaded crate docs in the OS-specific user cache directory (~/Library/Caches/bookworm/crates on macOS, ~/.cache/bookworm/crates on Linux) rather than the system temp directory. This makes downloaded documentation persist across reboots and easy to locate or wipe.

A new default_crates_root() function (backed by
directories::ProjectDirs) centralises this logic and is used by both the download function and the query client, replacing the two independent env::temp_dir() calls that were scattered across the codebase.

The sanitize function was also rewritten to use structural detection instead of matching against the crate name. Previously it kept only a directory whose name exactly matched the crate name, which silently deleted docs for crates with hyphenated names (e.g. ra-ap-rustc_lexer ships docs under ra_ap_rustc_lexer/) or a custom [lib] name = "…" declaration. The new logic keeps any directory that contains a top-level index.html (which is what rustdoc emits for real crate docs), plus src/ and implementors/ by allow-list. Target-triple wrapper directories produced by multi-platform docsets lack a direct index.html and are removed.

JeanMertz added 2 commits May 20, 2026 15:32
Cache downloaded crate docs in the OS-specific user cache directory
(`~/Library/Caches/bookworm/crates` on macOS, `~/.cache/bookworm/crates`
on Linux) rather than the system temp directory. This makes downloaded
documentation persist across reboots and easy to locate or wipe.

A new `default_crates_root()` function (backed by
`directories::ProjectDirs`) centralises this logic and is used by both
the `download` function and the `query` client, replacing the two
independent `env::temp_dir()` calls that were scattered across the
codebase.

The `sanitize` function was also rewritten to use structural detection
instead of matching against the crate name. Previously it kept only a
directory whose name exactly matched the crate name, which silently
deleted docs for crates with hyphenated names (e.g. `ra-ap-rustc_lexer`
ships docs under `ra_ap_rustc_lexer/`) or a custom `[lib] name = "…"`
declaration. The new logic keeps any directory that contains a top-level
`index.html` (which is what rustdoc emits for real crate docs), plus
`src/` and `implementors/` by allow-list. Target-triple wrapper
directories produced by multi-platform docsets lack a direct
`index.html` and are removed.

Signed-off-by: Jean Mertz <git@jeanmertz.com>
Signed-off-by: Jean Mertz <git@jeanmertz.com>
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