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