Skip to content

fix: handle symlinks in WriteFileAtomic#307

Open
utafrali wants to merge 1 commit intoGentleman-Programming:mainfrom
utafrali:fix/issue-306-error-in-the-sync-uninstall-commands-for
Open

fix: handle symlinks in WriteFileAtomic#307
utafrali wants to merge 1 commit intoGentleman-Programming:mainfrom
utafrali:fix/issue-306-error-in-the-sync-uninstall-commands-for

Conversation

@utafrali
Copy link
Copy Markdown
Contributor

Linked Issue

Closes #306

PR Type

  • bug fix
  • feature
  • refactor
  • docs
  • other

Summary

Was hitting errors when writing to symlinked config files, which breaks dotfile managers like stow and chezmoi. The issue was WriteFileAtomic was treating symlinks as regular files and potentially replacing them instead of updating the target.

Added symlink resolution so we write to the actual file and preserve the symlink.

Changes

File Description
internal/components/filemerge/writer.go Added readComparableFile() helper to resolve symlinks, updated WriteFileAtomic() to follow symlinks before reading/writing
internal/components/filemerge/writer_test.go Added TestWriteFileAtomic_PreservesSymlink to verify writes update the target while symlinks are preserved

Test Plan

Added TestWriteFileAtomic_PreservesSymlink which creates a symlink, writes through it, and verifies the target file is updated while the symlink stays intact. Existing tests pass.

@utafrali utafrali force-pushed the fix/issue-306-error-in-the-sync-uninstall-commands-for branch from 65fcd71 to c9984a8 Compare April 14, 2026 20:42
@fjpalacios
Copy link
Copy Markdown

I also use Stow to sync my dotfiles, and this error is a real headache. Thanks for the PR, and I hope it gets reviewed soon.

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.

Error in the sync/uninstall commands for when using symlinks for dotfiles

2 participants