Skip to content

fix(init): preserve settings.json symlink during atomic write - #2088

Merged
KuSh merged 2 commits into
rtk-ai:developfrom
ChrisGVE:fix/init-preserve-settings-symlink
May 31, 2026
Merged

KuSh merged 2 commits into
rtk-ai:developfrom
ChrisGVE:fix/init-preserve-settings-symlink

Conversation

@ChrisGVE

@ChrisGVE ChrisGVE commented May 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • atomic_write() replaced symlinked settings.json with a regular file, breaking setups that symlink config files (e.g. dotfile managers, multi-machine sync)
  • Now resolves symlink targets before the tempfile+rename so the link itself is preserved

Closes #653

Supersedes #675 — rebased on current develop. The portable hook path change from #675 is no longer needed since the codebase moved from shell scripts to rtk hook claude binary command.

Changes Made

  • Added resolve_atomic_target() that detects symlinks and resolves to their target (absolute or relative)
  • Updated atomic_write() to write through to the resolved target
  • Added 2 unix-specific tests for absolute and relative symlink preservation

Testing

  • cargo fmt --all --check
  • cargo clippy --all-targets — no warnings
  • cargo test --all — 1942 passed, 6 ignored
  • Specific tests: cargo test init::tests::test_atomic_write
  • Verified both fixes merge cleanly together (1947 tests pass combined)

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • No breaking changes introduced
  • Tests added for new functionality

@CLAassistant

CLAassistant commented May 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@ChrisGVE
ChrisGVE force-pushed the fix/init-preserve-settings-symlink branch from 7c206e6 to 6fc6ad0 Compare May 25, 2026 14:45
@ChrisGVE

Copy link
Copy Markdown
Contributor Author

@aeppling may I ask you to review this PR, this has been in the list for long and would help many user if it could be integrated into rtk. Thank you for your great work and for your time reviewing this PR.

atomic_write() replaced symlinked settings.json with a regular file.
Now resolves symlink targets before the tempfile+rename so the link
itself is preserved and the real file gets updated.

Covers both absolute and relative symlink targets.

Closes rtk-ai#653
@ChrisGVE
ChrisGVE force-pushed the fix/init-preserve-settings-symlink branch from 6fc6ad0 to cf7e5fd Compare May 26, 2026 08:23
Comment thread src/hooks/init.rs Outdated
@KuSh

KuSh commented May 31, 2026

Copy link
Copy Markdown
Collaborator

Hi, thanks for your contribution!
As it is a rebase of someone else submission, you'll have to add "Co-authored-by" trailer to the commit's message.

Simplify resolve_atomic_target() per review feedback — fs::canonicalize
handles chained symlinks, relative paths, and all edge cases.

Co-authored-by: Roopesh <roopesh1724989@gmail.com>
@ChrisGVE

Copy link
Copy Markdown
Contributor Author

Thanks @KuSh for the review! Both items addressed:

  1. fs::canonicalize — replaced custom resolve_atomic_target() with fs::canonicalize + fallback for non-existent paths (new file creation). Handles chained symlinks, relative paths, all edge cases.

  2. Co-authored-by — added Co-authored-by: Roopesh <roopesh1724989@gmail.com> trailer (original author of fix(init): preserve settings.json symlink and portable hook path #675).

All tests green: cargo fmt, cargo clippy, cargo test — 1951 passed.

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@KuSh
KuSh merged commit f1474b4 into rtk-ai:develop May 31, 2026
11 checks passed
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.

"rtk init --global" breaks symlink

3 participants