Repository navigation
fix: create missing XDG state directories for the default state path - #118
Merged
Merged
Conversation
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
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.
Fixes #111
Why
On a fresh system
~/.local/state(or$XDG_STATE_HOME) may not exist yet. The state store only ever created its leafsendspin-clidirectory, 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
StateStoretakes acreate_parentsflag.main.cppsets it only when--state-dirwas not given, so the default XDG path gets its missing ancestors created, at 0700.--state-dirbehaves as before: only the leaf is created, so a mistyped parent still fails visibly.make_directory()moves up to the parent only aftermkdirfails withENOENT, so directories that already exist are never touched and keep their permissions, as the spec requires.\, so anXDG_STATE_HOMEwritten with backslashes walks up correctly.Testing
StateStore.CreatesMissingAncestorsWhenAsked: writes two directories below an existing one and checks both new directories are 0700.AMissingParentDirectoryFailsstill covers the explicit case.-Werror): 549/549 passed.-Werror): 541/541 passed (the existing symlink test is skipped, as before).HOMEpointing at an empty directory andXDG_STATE_HOMEunset, the player created.local,.local/stateandsendspin-cliat 0700 and the state file at 0600.