MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / resolveCommandSymLink

Function resolveCommandSymLink

src/services/command/commands.ts:36–70  ·  view source on GitHub ↗

* Recursively resolve a symbolic link and collect command file info

(symlinkPath: string, fileInfo: CommandFileInfo[], depth: number)

Source from the content-addressed store, hash-verified

34 * Recursively resolve a symbolic link and collect command file info
35 */
36async function resolveCommandSymLink(symlinkPath: string, fileInfo: CommandFileInfo[], depth: number): Promise<void> {
37 // Avoid cyclic symlinks
38 if (depth > MAX_DEPTH) {
39 return
40 }
41 try {
42 // Get the symlink target
43 const linkTarget = await fs.readlink(symlinkPath)
44 // Resolve the target path (relative to the symlink location)
45 const resolvedTarget = path.resolve(path.dirname(symlinkPath), linkTarget)
46
47 // Check if the target is a file (use lstat to detect nested symlinks)
48 const stats = await fs.lstat(resolvedTarget)
49 if (stats.isFile()) {
50 // Only include markdown files
51 if (isMarkdownFile(resolvedTarget)) {
52 // For symlinks to files, store the symlink path as original and target as resolved
53 fileInfo.push({ originalPath: symlinkPath, resolvedPath: resolvedTarget })
54 }
55 } else if (stats.isDirectory()) {
56 // Read the target directory and process its entries
57 const entries = await fs.readdir(resolvedTarget, { withFileTypes: true })
58 const directoryPromises: Promise<void>[] = []
59 for (const entry of entries) {
60 directoryPromises.push(resolveCommandDirectoryEntry(entry, resolvedTarget, fileInfo, depth + 1))
61 }
62 await Promise.all(directoryPromises)
63 } else if (stats.isSymbolicLink()) {
64 // Handle nested symlinks
65 await resolveCommandSymLink(resolvedTarget, fileInfo, depth + 1)
66 }
67 } catch {
68 // Skip invalid symlinks
69 }
70}
71
72/**
73 * Recursively resolve directory entries and collect command file paths

Callers 1

Calls 3

isMarkdownFileFunction · 0.85
allMethod · 0.80

Tested by

no test coverage detected