fix: handle dangling symlinks in restorePkgSymlink#57
Conversation
existsSync follows symlinks and returns false for dangling ones, so symlinkSync throws EEXIST when trying to create over a stale link. Use lstatSync to detect and remove dangling symlinks before re-creating.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughrestorePkgSymlink now uses lstatSync to detect symlinks and distinguishes dangling symlinks from valid ones; dangling symlinks are unlinked before recreation, valid symlinks and non-symlink entries are left untouched. A unit test suite exercising five scenarios was added. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/core/prepare.ts`:
- Around line 39-52: The catch block in restorePkgSymlink is currently
swallowing all errors from lstatSync/unlinkSync and proceeding to create a
symlink; change the empty catch to catch the error (e.g., catch (err)) and only
treat ENOENT as “path missing” (allowing execution to continue to symlinkSync);
for any other err.code (permissions, EIO, etc.) rethrow the error so the real
failure is not masked. Ensure you reference the same functions (lstatSync,
unlinkSync, symlinkSync) when updating the error handling.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7a282428-a483-419c-9d7d-b51b82f0e82b
📒 Files selected for processing (2)
src/core/prepare.tstest/unit/prepare-restore.test.ts
Return early on permission/IO errors instead of swallowing them.
Description
restorePkgSymlinkcrashes with EEXIST when the.skilld/pkgsymlink exists but points to a deleted target (dangling).existsSyncfollows symlinks and returnsfalsefor dangling ones, so the guard passes through butsymlinkSyncsees the path already exists on disk.This happens during
skilld prepareafter cleaningnode_modulesand reinstalling - the old symlink is still on disk, target is gone,existsSyncsays "nothing here",symlinkSyncdisagrees.Fixed by using
lstatSync(doesn't follow symlinks) to detect and remove dangling symlinks before re-creating. Same patternlinkPkgincache/storage.tsalready uses.Linked Issues
Additional context
5 unit tests added covering: dangling symlink, valid symlink skip, no prior link, missing skill dir, real file at path.
Summary by CodeRabbit
Bug Fixes
Tests