fix(fs): replace execSync and fsync workarounds with atomic async FsHelpers operations to avoid XFS races and shell dependencies

This commit is contained in:
2026-03-05 14:01:00 +00:00
parent 4f8443d33f
commit 49d62e20a4
4 changed files with 24 additions and 48 deletions

View File

@@ -1,8 +1,5 @@
import type { CompilerOptions, Diagnostic, Program } from 'typescript';
import typescript from 'typescript';
import * as fs from 'fs';
import * as path from 'path';
import { execSync } from 'child_process';
import * as smartdelay from '@push.rocks/smartdelay';
import * as smartpromise from '@push.rocks/smartpromise';
import * as smartpath from '@push.rocks/smartpath';
@@ -370,18 +367,7 @@ export class TsCompiler {
// Perform unpack if compilation succeeded
if (result.errorSummary.totalErrors === 0) {
// Force XFS to commit all pending directory entries before unpacking.
// TypeScript's writeFileSync creates entries that may reside in XFS's
// delayed log. Without sync, readdir can return partial results.
execSync('sync');
this.syncDirectoryTree(destDir);
try {
await performUnpack(pattern, destDir, this.cwd);
} catch (unpackErr: any) {
console.error(` ⚠️ Unpack error for ${destPath}: ${unpackErr.message}`);
}
await performUnpack(pattern, destDir, this.cwd);
successfulOutputDirs.push(destDir);
}
@@ -504,27 +490,6 @@ export class TsCompiler {
return success;
}
/**
* Recursively fsync all directories in a tree.
* Forces XFS to commit pending directory entries from its log.
*/
private syncDirectoryTree(dirPath: string): void {
try {
const fd = fs.openSync(dirPath, 'r');
fs.fsyncSync(fd);
fs.closeSync(fd);
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
for (const entry of entries) {
if (entry.isDirectory()) {
this.syncDirectoryTree(path.join(dirPath, entry.name));
}
}
} catch {
// Ignore errors (directory may not exist)
}
}
/**
* Merge multiple error summaries into one
*/