MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / writeFileSyncAndFlush_DEPRECATED

Function writeFileSyncAndFlush_DEPRECATED

source code/utils/file.ts:364–480  ·  view source on GitHub ↗
(
  filePath: string,
  content: string,
  options: { encoding: BufferEncoding; mode?: number } = { encoding: 'utf-8' },
)

Source from the content-addressed store, hash-verified

362 * Sync file writes block the event loop and cause performance issues.
363 */
364export function writeFileSyncAndFlush_DEPRECATED(
365 filePath: string,
366 content: string,
367 options: { encoding: BufferEncoding; mode?: number } = { encoding: 'utf-8' },
368): void {
369 const fs = getFsImplementation()
370
371 // Check if the target file is a symlink to preserve it for all users
372 // Note: We don't use safeResolvePath here because we need to manually handle
373 // symlinks to ensure we write to the target while preserving the symlink itself
374 let targetPath = filePath
375 try {
376 // Try to read the symlink - if successful, it's a symlink
377 const linkTarget = fs.readlinkSync(filePath)
378 // Resolve to absolute path
379 targetPath = isAbsolute(linkTarget)
380 ? linkTarget
381 : resolve(dirname(filePath), linkTarget)
382 logForDebugging(`Writing through symlink: ${filePath} -> ${targetPath}`)
383 } catch {
384 // ENOENT (doesn't exist) or EINVAL (not a symlink) — keep targetPath = filePath
385 }
386
387 // Try atomic write first
388 const tempPath = `${targetPath}.tmp.${process.pid}.${Date.now()}`
389
390 // Check if target file exists and get its permissions (single stat, reused in both atomic and fallback paths)
391 let targetMode: number | undefined
392 let targetExists = false
393 try {
394 targetMode = fs.statSync(targetPath).mode
395 targetExists = true
396 logForDebugging(`Preserving file permissions: ${targetMode.toString(8)}`)
397 } catch (e) {
398 if (!isENOENT(e)) throw e
399 if (options.mode !== undefined) {
400 // Use provided mode for new files
401 targetMode = options.mode
402 logForDebugging(
403 `Setting permissions for new file: ${targetMode.toString(8)}`,
404 )
405 }
406 }
407
408 try {
409 logForDebugging(`Writing to temp file: ${tempPath}`)
410
411 // Write to temp file with flush and mode (if specified for new file)
412 const writeOptions: {
413 encoding: BufferEncoding
414 flush: boolean
415 mode?: number
416 } = {
417 encoding: options.encoding,
418 flush: true,
419 }
420 // Only set mode in writeFileSync for new files to ensure atomic permission setting
421 if (!targetExists && options.mode !== undefined) {

Callers 4

saveConfigFunction · 0.85
saveConfigWithLockFunction · 0.85
writeTextContentFunction · 0.85
updateSettingsForSourceFunction · 0.85

Calls 6

getFsImplementationFunction · 0.85
logForDebuggingFunction · 0.85
isENOENTFunction · 0.85
logEventFunction · 0.85
resolveFunction · 0.70
toStringMethod · 0.65

Tested by

no test coverage detected