Skip to content
This repository was archived by the owner on Sep 1, 2026. It is now read-only.

Fix watches on symlinked directories - #4376

Merged
Jake Bailey (jakebailey) merged 14 commits into
mainfrom
copilot/fix-symlinks-in-watch-mode
Jun 22, 2026
Merged

Jake Bailey (jakebailey) merged 14 commits into
mainfrom
copilot/fix-symlinks-in-watch-mode

Conversation

Copilot AI commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

Watch mode could fail on Bun-style node_modules layouts where requested watch roots are symlinks to package directories. Watchers now resolve a symlinked root to its physical directory for OS subscriptions while preserving the caller-visible symlink path in emitted events.

  • Watch root handling

    • Detect when the requested watch root is a symlink or Windows reparse point.
    • Resolve the physical watch path through osvfs helpers instead of using filepath.EvalSymlinks directly.
    • Keep walkDir from following symlinks, including symlinked roots.
  • Watcher backends

    • Apply symlinked-root path rebasing across watcher backends, not just fanotify.
    • Keep original requested paths in event delivery while using physical paths for OS-level subscriptions and recursive traversal.
  • Regression coverage

    • Added cross-backend coverage for subscribing to a symlinked directory and receiving child updates.
    • Added coverage that walkDir does not follow a symlinked root directory.

Example layout now supported:

node_modules/effect -> ../../../node_modules/.bun/[email protected]/node_modules/effect/

Copilot AI changed the title [WIP] Fix watch mode symlink resolution in 7.0.1-rc binary Fix fanotify watches on symlinked directories Jun 19, 2026
Comment thread internal/fswatch/fanotify_linux_test.go Resolved
Comment thread internal/fswatch/walkdir_unix.go Resolved
Comment thread internal/fswatch/fanotify_linux.go Resolved
Comment thread internal/fswatch/fanotify_linux.go Resolved
Copilot AI changed the title Fix fanotify watches on symlinked directories Fix watches on symlinked directories Jun 19, 2026
@jakebailey

Copy link
Copy Markdown
Member

Copilot Windows failure

	github.com/microsoft/typescript-go/internal/fourslash/tests/util		coverage: 0.0% of statements
--- FAIL: TestWalkDirDoesNotFollowRootSymlinkedDir (0.00s)
    --- FAIL: TestWalkDirDoesNotFollowRootSymlinkedDir/native (0.00s)
        walkdir_test.go:51: expected error for root symlinked directory
FAIL
coverage: 0.5% of statements in ./...

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Copilot Windows failure

...

Fixed in 5b44de9. The Windows walkDir root check now rejects reparse-point roots, matching the generic implementation and the test expectation.

@jakebailey
Jake Bailey (jakebailey) marked this pull request as ready for review June 19, 2026 21:21
Copilot AI review requested due to automatic review settings June 19, 2026 21:21
@jakebailey

Copy link
Copy Markdown
Member

This PR basically just allows directory watches on dirs that are symlinks. It turns out that Node previously allowed such a thing. And TS treats symlinks to dirs as dirs, so it all "worked".

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes watch-mode behavior when the requested watch root is a symlink (or Windows reparse point), by subscribing at the physical target path for OS-level watching while rebasing delivered event paths back under the caller-provided (symlink) root.

Changes:

  • Introduces internal/nativepath helpers for Realpath and IsSymlinkOrReparsePoint, and routes OS VFS realpath/reparse-point checks through them.
  • Adds dirWatch.physicalDir plus path rebasing utilities, and applies them across fswatch backends (inotify/fanotify/kqueue/fsevents/windows).
  • Adds regression tests for symlinked-root subscriptions and ensures userspace recursive walking does not follow symlinked roots/descendants.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/vfs/osvfs/reparsepoint_other.go Removes non-Windows stub in favor of centralized nativepath-based implementation.
internal/vfs/osvfs/realpath_other.go Removes fallback realpath implementation from osvfs (moved to nativepath).
internal/vfs/osvfs/os.go Switches osvfs realpath/reparse-point detection to internal/nativepath.
internal/nativepath/symlink_windows.go Provides IsSymlinkOrReparsePoint implementation for Windows (reparse points).
internal/nativepath/symlink_windows_test.go Updates tests/benchmarks for the renamed exported Windows helper.
internal/nativepath/symlink_other.go Adds non-Windows symlink detection via os.Lstat.
internal/nativepath/realpath_windows.go Moves/exports Windows realpath implementation as nativepath.Realpath.
internal/nativepath/realpath_other.go Adds non-win/linux/darwin fallback Realpath using filepath.EvalSymlinks.
internal/nativepath/realpath_linux.go Moves/exports Linux fast realpath implementation (O_PATH + /proc/self/fd).
internal/nativepath/realpath_darwin.go Moves/exports Darwin realpath implementation.
internal/nativepath/eintr_unix.go Moves EINTR-retry helper to nativepath for unix realpath implementations.
internal/fswatch/windows.go Subscribes/validates/stats using physicalDir while emitting paths under logical dir.
internal/fswatch/watcher.go Adds physicalDir to dirWatch and introduces path rebasing for events vs OS subscription paths.
internal/fswatch/watcher_test.go Adds cross-backend tests for symlinked-root subscriptions and descendant-symlink behavior.
internal/fswatch/walkdir_windows.go Prevents treating reparse-point roots as directories in Windows walkDir.
internal/fswatch/walkdir_test.go Adds coverage that walkDir rejects a symlinked root directory.
internal/fswatch/kqueue.go Tracks both logical and physical paths per entry; reads disk state from physical paths while emitting logical paths.
internal/fswatch/inotify_linux.go Rebases watch paths vs delivered paths; watches physical directories while emitting logical paths.
internal/fswatch/fsevents_darwin.go Rebases callback paths to logical roots while using physical roots for subscription/stat.
internal/fswatch/fanotify_linux.go Uses physical paths for marks/handles and rebases to logical paths for event delivery.
internal/fswatch/CHANGES.md Documents the new behavior for symlinked watch roots.
.golangci.yml Extends the linter configuration path matcher to include internal/nativepath.
Comments suppressed due to low confidence (1)

internal/nativepath/symlink_windows_test.go:183

  • mklink detects the Windows "symlink privilege not held" case by matching err.Error() text. That message can be localized or change across Windows/Go versions, making the test flaky. Prefer checking the underlying errno (e.g. errors.Is(err, syscall.ERROR_PRIVILEGE_NOT_HELD) or via *os.LinkError) and then skipping.

Comment thread internal/fswatch/walkdir_test.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.

Comment thread internal/fswatch/watcher.go Resolved
@andrewbranch

Copy link
Copy Markdown
Member

lspwatcher handles this itself, so that special handling should be removed.

@jakebailey

Copy link
Copy Markdown
Member

Indeed, yes.

@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queue Jun 22, 2026
Merged via the queue into main with commit 133d33a Jun 22, 2026
21 checks passed
@jakebailey
Jake Bailey (jakebailey) deleted the copilot/fix-symlinks-in-watch-mode branch June 22, 2026 18:23
Ryan Hart (rhart92) pushed a commit to rhart92/typescript-go that referenced this pull request Aug 2, 2026
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: jakebailey <[email protected]>
Jake Bailey (jakebailey) added a commit to jakebailey/TypeScript that referenced this pull request Aug 13, 2026
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: jakebailey <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7.0.1-rc binary in watch mode fails to resolve symlinks in node_modules

4 participants