| 44 | const MACOS_NOISE = new Set(['.DS_Store', '.AppleDouble', '.LSOverride']); |
| 45 | |
| 46 | export class FsService extends Disposable implements IFsService { |
| 47 | readonly _serviceBrand: undefined; |
| 48 | |
| 49 | protected gitignoreCache = new Map<string, Ignore>(); |
| 50 | |
| 51 | constructor(@ISessionService protected readonly sessions: ISessionService) { |
| 52 | super(); |
| 53 | } |
| 54 | |
| 55 | override dispose(): void { |
| 56 | this.gitignoreCache.clear(); |
| 57 | super.dispose(); |
| 58 | } |
| 59 | |
| 60 | async list(sessionId: string, req: FsListRequest): Promise<FsListResponse> { |
| 61 | const session = await this.sessions.get(sessionId); |
| 62 | const cwd = session.metadata.cwd; |
| 63 | const safe = await resolveSafePath(cwd, req.path); |
| 64 | |
| 65 | let topStat: import('node:fs').Stats; |
| 66 | try { |
| 67 | topStat = await fs.stat(safe.absolute); |
| 68 | } catch (err) { |
| 69 | throw mapStatError(err, req.path); |
| 70 | } |
| 71 | if (!topStat.isDirectory()) { |
| 72 | |
| 73 | throw new FsPathNotFoundError(req.path); |
| 74 | } |
| 75 | |
| 76 | const realCwd = await fs.realpath(cwd); |
| 77 | const matcher = req.follow_gitignore ? await this.matcher(realCwd) : undefined; |
| 78 | |
| 79 | const items: FsEntry[] = []; |
| 80 | const childrenByPath: Record<string, FsEntry[]> = {}; |
| 81 | let truncated = false; |
| 82 | |
| 83 | interface QueueEntry { |
| 84 | absPath: string; |
| 85 | |
| 86 | relPath: string; |
| 87 | depthRemaining: number; |
| 88 | } |
| 89 | const queue: QueueEntry[] = [ |
| 90 | { |
| 91 | absPath: safe.absolute, |
| 92 | relPath: safe.relative === '.' ? '' : safe.relative, |
| 93 | depthRemaining: req.depth, |
| 94 | }, |
| 95 | ]; |
| 96 | |
| 97 | while (queue.length > 0) { |
| 98 | const entry = queue.shift()!; |
| 99 | let dirents: import('node:fs').Dirent[]; |
| 100 | try { |
| 101 | dirents = await fs.readdir(entry.absPath, { withFileTypes: true }); |
| 102 | } catch (err) { |
| 103 |
nothing calls this directly
no outgoing calls
no test coverage detected