MCPcopy
hub / github.com/21st-dev/1code / readFile

Function readFile

src/main/lib/git/security/secure-fs.ts:283–295  ·  view source on GitHub ↗

* 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",
	)

Source from the content-addressed store, hash-verified

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.

Callers 5

repoUsesLfsFunction · 0.85
readJsonFileFunction · 0.85
readFileBufferFunction · 0.85
readLatestTokenCountInfoFunction · 0.85
files.tsFile · 0.85

Calls 3

assertRegisteredWorktreeFunction · 0.90
resolvePathInWorktreeFunction · 0.90
assertRealpathInWorktreeFunction · 0.85

Tested by

no test coverage detected