Skip to content

fix: use lstat instead of stat to detect symlinks in getFileMode#1200

Open
FuturizeRush wants to merge 1 commit intoanthropics:mainfrom
FuturizeRush:fix/use-lstat-for-symlink-detection
Open

fix: use lstat instead of stat to detect symlinks in getFileMode#1200
FuturizeRush wants to merge 1 commit intoanthropics:mainfrom
FuturizeRush:fix/use-lstat-for-symlink-detection

Conversation

@FuturizeRush
Copy link
Copy Markdown

Summary

Replace stat() with lstat() in getFileMode() so symlinks are correctly detected and committed with Git mode 120000.

Bug

src/mcp/github-file-ops-server.ts:170 uses stat(), which follows symlinks and reports the target file's type. isSymbolicLink() on a stat() result always returns false.

const fileStat = await stat(filePath);   // follows symlink → sees target
// ...
} else if (fileStat.isSymbolicLink()) {  // always false with stat()
    return "120000";
}

Symlinks are committed as regular files (mode 100644) instead of symlinks (mode 120000).

Fix

stat()lstat(). lstat() does not follow symlinks, so isSymbolicLink() correctly returns true.

Verified with Node.js

stat('/tmp/test-symlink').isSymbolicLink():  false  ← follows symlink
lstat('/tmp/test-symlink').isSymbolicLink(): true   ← sees symlink itself

Test plan

  • tsc --noEmit passes
  • Tested with real symlink: stat() returns false, lstat() returns true
  • Regular files and directories unaffected (lstat() behaves identically to stat() for non-symlinks)

Node.js stat() follows symlinks and reports the target's type, so
fileStat.isSymbolicLink() always returns false. This causes symlinks
to be committed with mode 100644 (regular file) instead of 120000
(symbolic link), corrupting the file type in the Git tree.

lstat() does not follow symlinks, so isSymbolicLink() correctly
returns true for symlink entries.
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.

2 participants