Repository navigation
fix: follow symlinks in atomicWrite so linked state files stay linked - #6
Open
michel-slm wants to merge 1 commit into
Open
michel-slm wants to merge 1 commit into
michel-slm wants to merge 1 commit into
Conversation
Linking ~/.claude/plugins/codachi/memory.json into a synced folder, to carry pet progress between machines, stops working after the first write: the file becomes a plain local copy and the synced one stops updating, with nothing to say so. atomicWrite writes a temp file and renames it over the path, and a rename onto a symlink replaces the link itself. It now resolves the link first and writes the temp file next to its target, so the rename replaces the target and the link stays. A link whose target does not exist yet is followed too, rather than replaced. Plain files are written exactly as before. Assisted-by: Claude Code:claude-opus-5-5
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.
Problem
Linking
~/.claude/plugins/codachi/memory.jsoninto a synced folder (Nextcloud, Syncthing, a dotfiles repo) to carry pet progress between machines stops working after the first write.atomicWritewrites a temp file and renames it over the path, and a rename onto a symlink replaces the link itself, so the file silently becomes a plain local copy and the synced one stops updating. Seen in practice: the local count reached 20 sessions while the synced copy stayed at 10.Fix
atomicWriteresolves the link first and writes the temp file next to the link's target, so the rename replaces the target and the link stays. A link whose target does not exist yet is followed too (the target is created) rather than replaced. Plain files and missing files are written exactly as before.Before and after
The same check against the npm 0.3.0 package and against a build of this branch: in an isolated
HOME,memory.jsonis linked into a "synced" folder holdingtotalSessions: 7, and one session renders the statusline.Check script
Usage:
./symlink-check.sh <path to dist/index.js> <label>Tests
src/fs-utils.symlink.test.ts, 4 tests on a real temp directory (fs-utils.test.tsmocksnode:fsmodule-wide, so link behaviour needs its own file): an absolute link, a relative link, a dangling link, and a plain file leaving no temp files behind. Against the unmodifiedfs-utils.ts, the three link tests fail; the plain-file one passes on both.fs-utils.test.ts: itsnode:fsmock gainsrealpathSync/lstatSync/readlinkSync, defaulting to ENOENT.tscclean.Notes
## [Unreleased]section toCHANGELOG.md, so whichever merges second needs a trivial rebase there; I'm happy to do it.