Skip to content

fix: Prevent bootstrap from overwriting source files via symlinked parent dirs - #300

Merged
evansenter merged 2 commits into
mainfrom
fix/bootstrap-symlink-self-overwrite
Apr 5, 2026
Merged

fix: Prevent bootstrap from overwriting source files via symlinked parent dirs#300
evansenter merged 2 commits into
mainfrom
fix/bootstrap-symlink-self-overwrite

Conversation

@evansenter

Copy link
Copy Markdown
Owner

Summary

  • Adds a guard to symlink_dotfiles() that resolves destination paths through parent symlinks and skips when the resolved path matches the source file
  • Prevents bootstrap from replacing its own source files with circular self-symlinks when a parent directory in ~ is symlinked back into the repo (e.g., ~/.config/zellij/scripts/dotfiles/home/.config/zellij/scripts/)
  • Uses pwd -P consistently for both source and destination path resolution

Test plan

  • make check passes (lint, test, hooks, bootstrap — 104 tests)
  • Verified home/.config/zellij/scripts/sysload.sh stays a regular file after bootstrap re-run
  • Manual: create a symlinked parent dir scenario and confirm bootstrap skips correctly

🤖 Generated with Claude Code

…rent dirs

When a parent directory in ~ is symlinked back into the repo (e.g.,
~/.config/zellij/scripts/ → dotfiles/home/.config/zellij/scripts/),
the destination path resolves to the source file itself. Bootstrap would
then delete the source and create a circular self-symlink.

Resolve destination paths through parent symlinks and skip when they
match the source.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Prompt: evansenter/dotfiles/.../claude-review.md

Code Review

Clean fix for a real bug where bootstrap could create circular self-symlinks when a parent directory under ~ is itself symlinked back into the repo. The approach of resolving both source and destination via pwd -P and comparing is correct.

[Important] bootstrap.sh:162 - symlink_claude_dir() still uses pwd (not pwd -P) on this line, which means it is susceptible to the same symlinked-parent-dir issue this PR fixes in symlink_dotfiles(). For consistency and correctness, this should also use pwd -P.

[Suggestion] bootstrap.sh:140 - Silent continue here means the operator gets no feedback when a file is skipped due to a symlinked parent. Consider adding a log line to aid debugging, similar to the warning on line 134.

Verdict: REQUEST_CHANGES - symlink_claude_dir() has the same pwd vs pwd -P inconsistency that this PR fixes in symlink_dotfiles().


Automated review by Claude Code

Address claude-review feedback:
- symlink_claude_dir() had the same pwd vs pwd -P inconsistency
- Add log line when files are skipped due to symlinked parent dirs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@evansenter

Copy link
Copy Markdown
Owner Author

Feedback Addressed

Implemented

  • [Important] symlink_claude_dir() now uses pwd -P for consistent path resolution
  • [Suggestion] Added log line when files are skipped due to symlinked parent dirs

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Prompt: evansenter/dotfiles/.../claude-review.md

Code Review

Summary

Clean fix for circular self-symlink bug when a parent directory under ~ is symlinked back into the repo. The approach of resolving paths via pwd -P and comparing source to resolved destination is correct and minimal.

Previously Addressed (Filtered)

  • [Important] symlink_claude_dir() pwd -P consistency — Implemented ✓
  • [Suggestion] Log line for skipped files — Implemented ✓

Verdict

APPROVE - Previous feedback addressed, no new issues found.


Automated review by Claude Code

@evansenter
evansenter merged commit 58c82e6 into main Apr 5, 2026
6 checks passed
@evansenter
evansenter deleted the fix/bootstrap-symlink-self-overwrite branch April 5, 2026 16:25
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.

1 participant