fix(config): preserve symlinked config.json on atomic save#193
Open
FunJim wants to merge 1 commit into
Open
Conversation
When config.json is a symlink (e.g. managed by GNU stow into a dotfiles repo), os.replace(tmp_path, CONFIG_FILE) overwrote the link itself with a regular file — rename(2) operates on the path, not the symlink target. Resolve CONFIG_FILE via os.path.realpath() and place the tempfile next to the resolved target so the atomic rename updates the link's target in place. Covers regular-file, stowed-symlink, and dangling-symlink cases via new tests in test_config.py.
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.
Summary
~/Library/Application Support/Mouser/config.json(or the Linux equivalent) is a symlink — typically managed via GNU stow into a dotfiles repo —save_configwas clobbering the symlink with a regular file on every save.os.replace(tmp_path, CONFIG_FILE)callsrename(2), which by POSIX semantics replaces the symlink itself rather than following it.CONFIG_FILEviaos.path.realpath()and place the tempfile in the resolved target's directory, so the atomic rename updates the link's target in place. For regular files the realpath equals the original path, so behavior is unchanged.Test plan
python -m unittest discover -s tests— 499 tests passtests/test_config.pycover regular file, stowed symlink, and dangling symlink cases