fix(watcher): auto-sync changes inside symlinked directories (#770)#784
Open
dengzhongyuan365-dev wants to merge 1 commit into
Open
Conversation
…henry#770) The file watcher (Linux inotify strategy) did not follow directory symlinks when building its watch set, so a project dir symlinked into the workspace root was silently invisible to the watcher. Changes: 1. watcher.ts: watchTree() now detects isSymbolicLink() entries, resolves real targets with realpathSync(), and recursively watches directory symlinks. Guards against cycles with a visitedRealDirs Set — tracking regular dirs too so a symlink→already-visited-path is also detected. Mirrors the indexer's walk() in extraction/index.ts. 2. utils.ts: Added allowSymlinkedDirs parameter to validatePathWithinRoot(). When true, skips the realpath check that would reject watched symlinks whose targets live outside the lexical project root. All internal sync/index paths pass true here; user-facing paths (MCP layer) keep the existing strict validation. 3. extraction/index.ts: All internal sync/index paths now pass allowSymlinkedDirs: true so the watcher can read files from symlinked directories. 4. __tests__/watcher.test.ts: Added integration test for symlinked directory auto-sync, plus a symlink-cycle detection test. Signed-off-by: dengzhongyuan <dengzhongyuan@uniontech.com>
4557ab8 to
fa7ab38
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
visitedRealDirsSet, matching the indexer's existing patternvalidatePathWithinRoot()to allow watcher-sourced paths through without rejecting symlinked targets outside the lexical rootChanges
src/sync/watcher.tswatchTree()now detectsisSymbolicLink()entries, resolves real targets, and recursively watches directory symlinkssrc/utils.tsallowSymlinkedDirsparameter tovalidatePathWithinRoot()— skips realpath check when truesrc/extraction/index.tsallowSymlinkedDirs: true__tests__/watcher.test.tsTest Plan
Fixes #770