Skip to content

Use XDG_CACHE_HOME for the bootstrap cache directory#48

Merged
wolveix merged 2 commits into
masterfrom
feat/xdg-cache-home
Jun 5, 2026
Merged

Use XDG_CACHE_HOME for the bootstrap cache directory#48
wolveix merged 2 commits into
masterfrom
feat/xdg-cache-home

Conversation

@wolveix

@wolveix wolveix commented Jun 5, 2026

Copy link
Copy Markdown
Member

Summary

Implements XDG Base Directory support for the bootstrap disk cache, addressing #35.

The default cache location changes from $HOME/.openrdap to $XDG_CACHE_HOME/openrdap, falling back to $HOME/.cache/openrdap when XDG_CACHE_HOME is unset or not an absolute path (relative values are ignored per the XDG spec).

This keeps non-essential cache files out of $HOME and lets users clear the cache predictably via $XDG_CACHE_HOME.

Changes

  • bootstrap/cache/disk_cache.go: resolve the default Dir from $XDG_CACHE_HOME (or $HOME/.cache); InitDir now uses MkdirAll so the cache parent (e.g. ~/.cache) is created as needed.
  • bootstrap/cache/disk_cache_test.go: add TestNewDiskCacheDir covering XDG set / unset / relative.
  • Doc updates: bootstrap/client.go godoc, cli.go --cache-dir help, rdap.1 man page, README.md.

Notes

The legacy $HOME/.openrdap directory is not migrated or preferred. Since the bootstrap cache is regenerable, existing installs simply re-download the registry files once into the new location. Use --cache-dir to override.

Closes #35

Summary by CodeRabbit

  • Bug Fixes

    • Bootstrap cache now uses the system XDG cache location with improved directory creation and error handling.
  • Documentation

    • Updated README, CLI help text, and manual pages to reflect new cache directory defaults and usage table formatting.
  • Tests

    • Added tests validating cache directory resolution across XDG/HOME environment scenarios.

Default the disk cache to $XDG_CACHE_HOME/openrdap, falling back to
$HOME/.cache/openrdap when XDG_CACHE_HOME is unset or not absolute, instead
of $HOME/.openrdap. This keeps non-essential cache files out of $HOME and
lets users clear the cache predictably via $XDG_CACHE_HOME.

InitDir now uses MkdirAll so the cache parent (e.g. ~/.cache) is created as
needed.

Closes #35
@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 919d437b-d29d-4845-a6bb-cf7727bfc6d7

📥 Commits

Reviewing files that changed from the base of the PR and between 60b210e and 1fe21cd.

📒 Files selected for processing (1)
  • bootstrap/cache/disk_cache.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • bootstrap/cache/disk_cache.go

📝 Walkthrough

Walkthrough

Migrate bootstrap cache from $HOME/.openrdap/ to XDG Base Directory: $XDG_CACHE_HOME/openrdap/ with fallback $HOME/.cache/openrdap/. NewDiskCache() resolves XDG vs fallback. InitDir uses os.MkdirAll. Save always initializes dir, writes file, then reads modtime and updates lastLoadedModTime. Add TestNewDiskCacheDir for XDG/unset/relative cases. Update README, CLI help text, man page, and package docs.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title accurately summarizes main change: switching cache default from ~/.openrdap to XDG_CACHE_HOME/openrdap.
Linked Issues check ✅ Passed Implementation matches issue #35 requirements: defaults to ${XDG_CACHE_HOME:-~/.cache}/openrdap, respects XDG spec (ignores relative paths), documents the change, and allows override via --cache-dir.
Out of Scope Changes check ✅ Passed All changes directly support XDG cache implementation: code logic (disk_cache.go), tests (disk_cache_test.go), and documentation (README, cli.go, bootstrap/client.go, rdap.1).
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/xdg-cache-home

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
bootstrap/cache/disk_cache.go (1)

49-61: ⚡ Quick win

XDG resolution correct. Panic acceptable but could be clearer.

Lines 52-58 correctly ignore relative XDG_CACHE_HOME per spec, fall back to $HOME/.cache.

Line 55 panic when home dir unknown is harsh but defensible - environment is broken. Consider more specific message like "HOME environment variable not set or inaccessible" so user knows what's wrong.

🔍 Clearer panic message
-			panic("Can't determine your home directory")
+			panic("Cannot determine home directory: HOME environment variable not set or inaccessible")
bootstrap/cache/disk_cache_test.go (1)

17-47: 💤 Low value

Test coverage good. Cleanup error acceptable but could be explicit.

Lines 29-46 validate XDG scenarios correctly: absolute path used, unset falls back, relative ignored.

Line 25: Static analysis flagged unchecked os.RemoveAll error. In test cleanup, this is standard Go pattern - temp dir cleanup failure won't break test. Acceptable as-is, but can make intent explicit with _ = os.RemoveAll(home).

📝 Explicit ignore
-	defer os.RemoveAll(home)
+	defer func() { _ = os.RemoveAll(home) }()

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f2100dac-aab1-4db6-96c8-865e6db6bcc3

📥 Commits

Reviewing files that changed from the base of the PR and between 5d37d55 and 60b210e.

📒 Files selected for processing (6)
  • README.md
  • bootstrap/cache/disk_cache.go
  • bootstrap/cache/disk_cache_test.go
  • bootstrap/client.go
  • cli.go
  • rdap.1

@wolveix wolveix merged commit 8fa7e50 into master Jun 5, 2026
4 checks passed
@wolveix wolveix deleted the feat/xdg-cache-home branch June 5, 2026 16:14
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.

XDG_CACHE_HOME support

1 participant