All files / src/utils sync-directory.ts

100% Statements 8/8
100% Branches 2/2
100% Functions 1/1
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16256x           256x 469x 468x 466x 466x   466x      
import * as fs from 'node:fs';
 
/**
 * Flush a directory entry change (a rename into it) to disk, so the replaced file
 * survives a crash. Windows has no directory fsync; NTFS journals the rename.
 */
export async function syncDirectory(dir: string): Promise<void> {
  if (process.platform === 'win32') return;
  const handle = await fs.promises.open(dir, 'r');
  try {
    await handle.sync();
  } finally {
    await handle.close();
  }
}