Repository navigation
feat(cli): honour XDG_CONFIG_HOME for the config directory - #2064
Merged
Merged
Conversation
Users who keep their home directory clean expect CLIs to store config under XDG_CONFIG_HOME. The directory is now resolved once: an existing ~/.appwrite keeps winning so current installs never lose their sessions, otherwise an absolute XDG_CONFIG_HOME selects $XDG_CONFIG_HOME/appwrite, and ~/.appwrite stays the default. The update-check cache and APNs session directory follow the same resolution as prefs.json so nothing is split across two places. The e2e harness pins XDG_CONFIG_HOME inside its sandboxed HOME so an inherited value can never point it at real credentials.
3 tasks
🟢 Tier S · Ready to mergeThe CLI centralizes user-level state under a shared config directory, preserving an existing Latest changes: The newest commit removes the existence check for
📂 Walkthrough · 7
Reviewed the commits since |
Issue #131 asks for the home directory whenever the XDG base directory is missing, rather than creating it. Tests that sandbox HOME now clear XDG_CONFIG_HOME too, so a developer's own XDG preferences cannot leak into them.
Falling back to ~/.appwrite when XDG_CONFIG_HOME does not exist yet sends a user who points it at a new path to the home directory, and once ~/.appwrite exists it wins from then on. Apps create their XDG directories, so the missing-directory case now pins that and #131's fallback wording is deliberately not followed.
hansi-codes
Bot
dismissed
their stale review
October 16, 2026 07:44
The findings that requested changes are resolved. See the summary comment for what is still open.
2 tasks done
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.
What
The CLI now resolves its config directory once, in
config.GlobalDirectory, and every file it keeps there (prefs.json,update-check.json, the APNsapns/session directory) follows that one answer.~/.appwritealready exists~/.appwrite(unchanged, no migration)~/.appwrite,XDG_CONFIG_HOMEset to an absolute path (created on first write if missing)$XDG_CONFIG_HOME/appwrite~/.appwrite,XDG_CONFIG_HOMEunset, empty or relative~/.appwrite(unchanged default)Relative values are ignored, as the XDG Base Directory spec requires. #131 also suggests falling back to
~/.appwritewhenXDG_CONFIG_HOMEdoes not exist; this deliberately does not, because apps are expected to create their XDG directories, and a fallback would send a user who pointsXDG_CONFIG_HOMEat a new path to~/.appwrite, which then wins on every later run. macOS and Windows defaults are unchanged; they only move when the user setsXDG_CONFIG_HOMEthemselves. The wasm build resolves the same way through the existinghomeDir()shim.The e2e harness now pins
XDG_CONFIG_HOMEinside its sandboxedHOME, and every unit test that sandboxesHOMEwithout creating~/.appwrite(the fan-out test,TestGenerateEndpointFallsBackToTheDefaultand the completion tests'setHome) clears it, so an inherited value can never point a test at real credentials.Reproduction
Empty scratch
HOMEandXDG_CONFIG_HOME, then:Before (28.6.0), XDG is ignored:
After:
After, with a pre-existing
$HOME/.appwriteandXDG_CONFIG_HOMEset, the existing directory is still used:A signed-in command: scratch
HOME(with~/Librarysymlinked for the keychain), a copy of realprefs.jsonplaced at$XDG_CONFIG_HOME/appwrite/prefs.jsonwith.currentpointing at a staging session, thenappwrite whoami:Tests
TestGlobalPathFollowsXDGConfigHomecovers an existing~/.appwritewinning over XDG, an absoluteXDG_CONFIG_HOME, one that does not exist yet still being used, an unset one, and a relative one being ignored.TestGenerateEndpointFallsBackToTheDefaultfailed before this PR's isolation fix when run with an inheritedXDG_CONFIG_HOMEwhoseappwrite/prefs.jsonhas a custom endpoint (endpoint = "https://leaked.example/v1", want "https://cloud.appwrite.io/v1"). It now clearsXDG_CONFIG_HOME, and the fullgo test ./...passes with that polluted value set.TestGlobalWriteCreatesTheXDGDirectorychecks that the first write lands underXDG_CONFIG_HOMEand does not create~/.appwrite.main(the absolute XDG case and the write test) and pass here.php example.php cli,gofmt -l,go build ./...,go vet ./...,go test -race ./...,GOOS=js GOARCH=wasm go build -tags browser .,composer lint-twigandcomposer refactor:checkall pass locally.Fixes appwrite/sdk-for-cli#131
Closes #2066