Skip to content

Commit 744ee6e

Browse files
HavenDVclaude
andcommitted
Skip symlink directories to avoid traversal into virtual/mounted filesystems
Detects symlinks via ReparsePoint attribute and skips directory symlinks during scanning. Prevents traversal into Steam.app recursive bundles, CloudStorage network mounts, CoreSimulator recursive revlinks, and similar problematic paths. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c6067f7 commit 744ee6e

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/cli/Tiktoken.Cli/IO/FileScanner.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public IReadOnlyList<string> Scan(string rootPath)
113113
/// Length is NOT included because on macOS/Linux it triggers an extra stat() syscall
114114
/// per entry. We defer the stat call to after gitignore/filter checks pass.
115115
/// </summary>
116-
private readonly record struct DirEntry(string FullPath, bool IsDirectory);
116+
private readonly record struct DirEntry(string FullPath, bool IsDirectory, bool IsSymlink);
117117

118118
/// <summary>
119119
/// Enumerates all entries (files + directories) in a single readdir pass using
@@ -126,7 +126,8 @@ private static FileSystemEnumerable<DirEntry> EnumerateEntries(string dirPath)
126126
dirPath,
127127
static (ref FileSystemEntry entry) => new DirEntry(
128128
entry.ToFullPath(),
129-
entry.IsDirectory),
129+
entry.IsDirectory,
130+
entry.Attributes.HasFlag(FileAttributes.ReparsePoint)),
130131
new EnumerationOptions
131132
{
132133
IgnoreInaccessible = true,
@@ -194,6 +195,13 @@ private void ScanDirectory(
194195
{
195196
if (entry.IsDirectory)
196197
{
198+
// Skip symlink directories to avoid traversing into virtual/mounted
199+
// filesystems, symlink loops, and paths like Steam.app recursive bundles
200+
if (entry.IsSymlink)
201+
{
202+
continue;
203+
}
204+
197205
var dirName = Path.GetFileName(entry.FullPath);
198206

199207
if (!_noDefaultExcludes && DefaultExcludedDirs.Contains(dirName))

0 commit comments

Comments
 (0)