Skip to content

fix(config): write through a symlinked ~/.ssh/config - #125

Open
lord-helicon wants to merge 1 commit into
Adembc:mainfrom
lord-helicon:upstream-pr/fix-symlinked-config
Open

lord-helicon wants to merge 1 commit into
Adembc:mainfrom
lord-helicon:upstream-pr/fix-symlinked-config

Conversation

@lord-helicon

Copy link
Copy Markdown

Fixes #96.

When ~/.ssh/config is a symlink (for example into a dotfiles repo), saving renamed the temp file over the link itself. That replaced the symlink with a regular file and left the real file stale.

lazyssh now resolves the link first and atomically replaces its target. Backups still go next to the link in ~/.ssh, and a config that doesn't exist yet behaves as before.

Testing

  • TestAddServerKeepsSymlinkedConfig checks that the link survives, the target is updated, the original backup lands next to the link, and no extra files appear next to the target.
  • make build (gofumpt, vet, golangci-lint) and make test pass.

This PR is independent of my other two config fixes. The small helpers_test.go is identical in all three, so they merge cleanly in any order.

Saving renamed the temp file over ~/.ssh/config itself, replacing a
symlink (e.g. into a dotfiles repo) with a regular file and leaving the
real file stale. Resolve the link first and atomically replace its
target instead. Backups still go next to the link in ~/.ssh.

Fixes Adembc#96
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.

LazySSH breaks symbolic link to SSH config

1 participant