From 4feb074c03e9b93a4e7b1edca1b8db802be19480 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Thu, 5 Mar 2026 15:01:36 +0000 Subject: [PATCH] fix(mod_unpack): handle partial readdirSync results when moving nested directory entries and add diagnostic log --- changelog.md | 7 +++++++ ts/00_commitinfo_data.ts | 2 +- ts/mod_unpack/classes.tsunpacker.ts | 22 ++++++++++++++++------ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/changelog.md b/changelog.md index bce6b24..7fe4414 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2026-03-05 - 4.1.23 - fix(mod_unpack) +handle partial readdirSync results when moving nested directory entries and add diagnostic log + +- Loop over readdirSync results until the nested directory is empty to avoid missing entries from partial reads +- Count moved entries and print a diagnostic message with the final destination entry count +- Keep removal of the now-empty nested directory (fs.rmdirSync) after moving contents + ## 2026-03-05 - 4.1.22 - fix(mod_compiler) improve logging of successful output directories to include a sorted list of entries and use a shortened relative path diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 3082e54..ea019a4 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@git.zone/tsbuild', - version: '4.1.22', + version: '4.1.23', description: 'A tool for compiling TypeScript files using the latest nightly features, offering flexible APIs and a CLI for streamlined development.' } diff --git a/ts/mod_unpack/classes.tsunpacker.ts b/ts/mod_unpack/classes.tsunpacker.ts index 46799f9..41d207f 100644 --- a/ts/mod_unpack/classes.tsunpacker.ts +++ b/ts/mod_unpack/classes.tsunpacker.ts @@ -116,17 +116,27 @@ export class TsUnpacker { } // Step 2: Move all contents from nested dir up to dest dir - const nestedEntries = fs.readdirSync(nestedPath); - for (const entry of nestedEntries) { - fs.renameSync( - path.join(nestedPath, entry), - path.join(this.destDir, entry), - ); + // Use a loop to handle any partial readdirSync results + let moved = 0; + while (true) { + const entries = fs.readdirSync(nestedPath); + if (entries.length === 0) break; + for (const entry of entries) { + fs.renameSync( + path.join(nestedPath, entry), + path.join(this.destDir, entry), + ); + moved++; + } } // Step 3: Remove the now-empty nested directory fs.rmdirSync(nestedPath); + // Diagnostic: verify final state + const finalEntries = fs.readdirSync(this.destDir); + console.log(` 📦 Unpacked ${this.sourceFolderName}: moved ${moved} entries, final: ${finalEntries.length} entries`); + return true; } }