MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / readTrailFile

Function readTrailFile

src/ui-server/api/trail-store.ts:254–275  ·  view source on GitHub ↗
(absolute: string, id: string)

Source from the content-addressed store, hash-verified

252}
253
254function readTrailFile(absolute: string, id: string): StoredTrail | null {
255 let fd: number | null = null;
256 try {
257 // O_NOFOLLOW closes the race between path validation and the actual open:
258 // replacing a checked file with a symlink must fail rather than follow it.
259 // O_NONBLOCK keeps a FIFO with no writer from parking the whole server on
260 // this open; a regular file ignores it, and `isFile()` below rejects the rest.
261 fd = fs.openSync(
262 absolute,
263 fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0)
264 );
265 const stat = fs.fstatSync(fd);
266 // A file too big to be a trail is skipped rather than read: this directory
267 // is inside the project, and something else may one day put a log in it.
268 if (!stat.isFile() || stat.size > MAX_TRAIL_FILE_BYTES) return null;
269 return parseTrail(id, fs.readFileSync(fd, 'utf-8'));
270 } catch {
271 return null;
272 } finally {
273 if (fd !== null) fs.closeSync(fd);
274 }
275}
276
277/** One trail by id, or `null` when there is no such file. */
278export function readStoredTrail(projectRoot: string, id: string): StoredTrail | null {

Callers 1

readStoredTrailFunction · 0.85

Calls 2

parseTrailFunction · 0.85
openSyncMethod · 0.45

Tested by

no test coverage detected