fix(mod_unpack): Use child_process.execSync (mv/rm) to perform unpack atomically, replacing async fs operations and logs to avoid ENOENT/partial directory listings on XFS
This commit is contained in:
@@ -1,5 +1,12 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2026-03-05 - 4.1.13 - fix(mod_unpack)
|
||||||
|
Use child_process.execSync (mv/rm) to perform unpack atomically, replacing async fs operations and logs to avoid ENOENT/partial directory listings on XFS
|
||||||
|
|
||||||
|
- Replaced async fs.promises.rename/rm and readdir/stat debugging with execSync rm -rf and mv operations for sequential, atomic moves
|
||||||
|
- Imported execSync from child_process and removed verbose console logging and extra fs checks
|
||||||
|
- Addresses race conditions observed on filesystems like XFS where libuv async operations can return partial results or ENOENT errors
|
||||||
|
|
||||||
## 2026-03-05 - 4.1.12 - fix(mod_compiler)
|
## 2026-03-05 - 4.1.12 - fix(mod_compiler)
|
||||||
replace runtime require calls with top-level imports and use execSync/path.join for filesystem sync and traversal
|
replace runtime require calls with top-level imports and use execSync/path.join for filesystem sync and traversal
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@git.zone/tsbuild',
|
name: '@git.zone/tsbuild',
|
||||||
version: '4.1.12',
|
version: '4.1.13',
|
||||||
description: 'A tool for compiling TypeScript files using the latest nightly features, offering flexible APIs and a CLI for streamlined development.'
|
description: 'A tool for compiling TypeScript files using the latest nightly features, offering flexible APIs and a CLI for streamlined development.'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as fs from 'fs';
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import { execSync } from 'child_process';
|
||||||
import { TsPublishConfig } from '../mod_config/index.js';
|
import { TsPublishConfig } from '../mod_config/index.js';
|
||||||
import { FsHelpers } from '../mod_fs/index.js';
|
import { FsHelpers } from '../mod_fs/index.js';
|
||||||
|
|
||||||
@@ -83,11 +83,10 @@ export class TsUnpacker {
|
|||||||
/**
|
/**
|
||||||
* Perform the unpack operation - flatten nested output directories.
|
* Perform the unpack operation - flatten nested output directories.
|
||||||
*
|
*
|
||||||
* Strategy: instead of listing entries and moving them individually (which is
|
* Uses shell commands (mv, rm) via execSync for reliability. Node.js async
|
||||||
* vulnerable to async readdir returning partial results under signal pressure),
|
* fs operations (rename, rm) can race on XFS filesystems where metadata
|
||||||
* we rename the entire nested directory out, remove the dest dir, then rename
|
* commits are delayed, causing ENOENT or partial directory listings.
|
||||||
* the nested directory back as the dest dir. This uses only rename operations
|
* Shell commands execute as direct syscalls without libuv's async layer.
|
||||||
* which are atomic at the kernel level.
|
|
||||||
*
|
*
|
||||||
* Returns true if unpacking was performed, false if skipped.
|
* Returns true if unpacking was performed, false if skipped.
|
||||||
*/
|
*/
|
||||||
@@ -103,40 +102,12 @@ export class TsUnpacker {
|
|||||||
const nestedPath = this.getNestedPath();
|
const nestedPath = this.getNestedPath();
|
||||||
const tempPath = this.destDir + '.__unpack_temp__';
|
const tempPath = this.destDir + '.__unpack_temp__';
|
||||||
|
|
||||||
// Log what we're about to do
|
// Use shell commands for atomic, sequential filesystem operations.
|
||||||
const nestedEntries = fs.readdirSync(nestedPath);
|
// This avoids race conditions between Node.js async fs operations on XFS.
|
||||||
console.log(` 📦 Unpacking ${this.sourceFolderName}/: ${nestedEntries.length} entries in nested dir`);
|
execSync(`rm -rf "${tempPath}"`, { stdio: 'ignore' });
|
||||||
console.log(` 📦 Entries: [${nestedEntries.join(', ')}]`);
|
execSync(`mv "${nestedPath}" "${tempPath}"`, { stdio: 'ignore' });
|
||||||
// Also list the dest dir to see what TypeScript created
|
execSync(`rm -rf "${this.destDir}"`, { stdio: 'ignore' });
|
||||||
const destEntries = fs.readdirSync(this.destDir);
|
execSync(`mv "${tempPath}" "${this.destDir}"`, { stdio: 'ignore' });
|
||||||
console.log(` 📦 destDir entries: [${destEntries.join(', ')}]`);
|
|
||||||
|
|
||||||
// Clean up any leftover temp dir from a previous failed unpack
|
|
||||||
await fs.promises.rm(tempPath, { recursive: true, force: true });
|
|
||||||
|
|
||||||
// Step 1: Rename the nested source folder out to a temp location.
|
|
||||||
// e.g. dist_ts/ts/ → dist_ts.__unpack_temp__/
|
|
||||||
await fs.promises.rename(nestedPath, tempPath);
|
|
||||||
|
|
||||||
// Verify step 1
|
|
||||||
const tempEntries = fs.readdirSync(tempPath);
|
|
||||||
console.log(` 📦 Step 1 (rename to temp): ${tempEntries.length} entries in temp`);
|
|
||||||
|
|
||||||
// Step 2: Remove the dest dir (which now only contains sibling folders
|
|
||||||
// like ts_interfaces/). Use recursive rm to handle any contents.
|
|
||||||
await fs.promises.rm(this.destDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
||||||
console.log(` 📦 Step 2 (remove dest): done`);
|
|
||||||
|
|
||||||
// Step 3: Rename the temp dir to the dest dir.
|
|
||||||
// e.g. dist_ts.__unpack_temp__/ → dist_ts/
|
|
||||||
await fs.promises.rename(tempPath, this.destDir);
|
|
||||||
|
|
||||||
// Verify final state
|
|
||||||
const finalEntries = fs.readdirSync(this.destDir);
|
|
||||||
const finalDirs = finalEntries.filter((e: string) => {
|
|
||||||
return fs.statSync(path.join(this.destDir, e)).isDirectory();
|
|
||||||
});
|
|
||||||
console.log(` 📦 Step 3 (rename to dest): ${finalEntries.length} entries (${finalDirs.length} dirs)`);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user