MCPcopy Create free account
hub / github.com/Noumena-Network/code / tryReadFileForSync

Function tryReadFileForSync

src/services/settingsSync/index.ts:395–413  ·  view source on GitHub ↗

* Try to read a file for sync, with size limit and error handling. * Returns null if file doesn't exist, is empty, or exceeds size limit.

(filePath: string)

Source from the content-addressed store, hash-verified

393 * Returns null if file doesn't exist, is empty, or exceeds size limit.
394 */
395async function tryReadFileForSync(filePath: string): Promise<string | null> {
396 try {
397 const stats = await stat(filePath)
398 if (stats.size > MAX_FILE_SIZE_BYTES) {
399 logForDiagnosticsNoPII('info', 'settings_sync_file_too_large')
400 return null
401 }
402
403 const content = await readFile(filePath, 'utf8')
404 // Check for empty/whitespace-only without allocating a trimmed copy
405 if (!content || /^\s*$/.test(content)) {
406 return null
407 }
408
409 return content
410 } catch {
411 return null
412 }
413}
414
415async function buildEntriesFromLocalFiles(
416 projectId: string | null,

Callers 1

Calls 3

statFunction · 0.85
logForDiagnosticsNoPIIFunction · 0.85
readFileFunction · 0.85

Tested by

no test coverage detected