Skip to content

fix: create missing XDG state directories for the default state path - #118

Merged
chrisuthe merged 1 commit into
mainfrom
fix/create-xdg-state-parents
Nov 10, 2026
Merged

chrisuthe merged 1 commit into
mainfrom
fix/create-xdg-state-parents

Conversation

@chrisuthe

Copy link
Copy Markdown
Member

Fixes #111

Why

On a fresh system ~/.local/state (or $XDG_STATE_HOME) may not exist yet. The state store only ever created its leaf sendspin-cli directory, so every write of the state file failed, and the player forgot its identity, pairings and volume across restarts. The XDG Base Directory spec asks applications to create a missing destination directory with mode 0700.

What

  • StateStore takes a create_parents flag. main.cpp sets it only when --state-dir was not given, so the default XDG path gets its missing ancestors created, at 0700.
  • An explicit --state-dir behaves as before: only the leaf is created, so a mistyped parent still fails visibly.
  • make_directory() moves up to the parent only after mkdir fails with ENOENT, so directories that already exist are never touched and keep their permissions, as the spec requires.
  • On Windows the parent split also accepts \, so an XDG_STATE_HOME written with backslashes walks up correctly.

Testing

  • New StateStore.CreatesMissingAncestorsWhenAsked: writes two directories below an existing one and checks both new directories are 0700. AMissingParentDirectoryFails still covers the explicit case.
  • Linux (WSL Ubuntu 24.04, gcc 13, -Werror): 549/549 passed.
  • Windows (clang-cl, -Werror): 541/541 passed (the existing symlink test is skipped, as before).
  • End to end on Linux: with HOME pointing at an empty directory and XDG_STATE_HOME unset, the player created .local, .local/state and sendspin-cli at 0700 and the state file at 0600.
  • clang-format 20.1.8 on the changed files.

On a system where ~/.local/state (or $XDG_STATE_HOME) does not exist yet,
every state write failed, because only the leaf sendspin-cli directory was
created. The XDG base directory spec asks applications to create a missing
destination directory at mode 0700.

Missing ancestors are now created, at 0700, when the path is the default one.
An explicit --state-dir still creates only its leaf, so a mistyped parent
keeps failing visibly. Existing directories are never touched.

Fixes #111
@chrisuthe
chrisuthe merged commit 66b4a08 into main Nov 10, 2026
20 checks passed
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.

Doesn't create "~/.local/state/" if non-existent

1 participant