* Read a file within a worktree. * * SECURITY: Enforces symlink-escape check. If the file is a symlink * pointing outside the worktree, this will throw PathValidationError. * * @throws PathValidationError with code "SYMLINK_ESCAPE" if file escapes worktree
( worktreePath: string, filePath: string, encoding: BufferEncoding = "utf-8", )
| 281 | * @throws PathValidationError with code "SYMLINK_ESCAPE" if file escapes worktree |
| 282 | */ |
| 283 | async readFile( |
| 284 | worktreePath: string, |
| 285 | filePath: string, |
| 286 | encoding: BufferEncoding = "utf-8", |
| 287 | ): Promise<string> { |
| 288 | assertRegisteredWorktree(worktreePath); |
| 289 | const fullPath = resolvePathInWorktree(worktreePath, filePath); |
| 290 | |
| 291 | // Block reads through symlinks that escape the worktree |
| 292 | await assertRealpathInWorktree(worktreePath, fullPath); |
| 293 | |
| 294 | return readFile(fullPath, encoding); |
| 295 | }, |
| 296 | |
| 297 | /** |
| 298 | * Read a file as a Buffer within a worktree. |
no test coverage detected