From 5cb374d9d744d1897389b7adc4915503e6f31800 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Mon, 26 Jun 2023 00:01:17 -0700 Subject: [PATCH 1/2] fix: Serialize walkAsync so isBinaryFile doesn't throw EMFILE: too many open files. --- src/util.ts | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/util.ts b/src/util.ts index 9a7e5c4..bd0682d 100644 --- a/src/util.ts +++ b/src/util.ts @@ -136,33 +136,32 @@ export async function walkAsync (dirPath: string): Promise { debugLog('Walking... ' + dirPath); async function _walkAsync (dirPath: string): Promise> { + const res: string[] = []; const children = await fs.readdir(dirPath); - return await Promise.all( - children.map(async (child) => { - const filePath = path.resolve(dirPath, child); - - const stat = await fs.stat(filePath); - if (stat.isFile()) { - switch (path.extname(filePath)) { - case '.cstemp': // Temporary file generated from past codesign - debugLog('Removing... ' + filePath); - await fs.remove(filePath); - return null; - default: - return await getFilePathIfBinary(filePath); - } - } else if (stat.isDirectory() && !stat.isSymbolicLink()) { - const walkResult = await _walkAsync(filePath); - switch (path.extname(filePath)) { - case '.app': // Application - case '.framework': // Framework - walkResult.push(filePath); - } - return walkResult; + for (const child of children) { + const filePath = path.resolve(dirPath, child); + const stat = await fs.stat(filePath); + if (stat.isFile()) { + switch (path.extname(filePath)) { + case '.cstemp': // Temporary file generated from past codesign + debugLog('Removing... ' + filePath); + await fs.remove(filePath); + break; + default: + await getFilePathIfBinary(filePath) && res.push(filePath); + break; } - return null; - }) - ); + } else if (stat.isDirectory() && !stat.isSymbolicLink()) { + const walkResult = await _walkAsync(filePath); + switch (path.extname(filePath)) { + case '.app': // Application + case '.framework': // Framework + walkResult.push(filePath); + } + res.push(walkResult); + } + } + return res; } const allPaths = await _walkAsync(dirPath); From 799da8266130754cd85c7cc01417ed0f07cb2844 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Mon, 26 Jun 2023 11:48:30 -0700 Subject: [PATCH 2/2] fix: Type error. --- src/util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.ts b/src/util.ts index bd0682d..3e8e9f1 100644 --- a/src/util.ts +++ b/src/util.ts @@ -136,7 +136,7 @@ export async function walkAsync (dirPath: string): Promise { debugLog('Walking... ' + dirPath); async function _walkAsync (dirPath: string): Promise> { - const res: string[] = []; + const res: DeepList = []; const children = await fs.readdir(dirPath); for (const child of children) { const filePath = path.resolve(dirPath, child);