Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Serialize walkAsync so isBinaryFile doesn't throw EMFILE: too many open files. #286

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 24 additions & 25 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,33 +136,32 @@ export async function walkAsync (dirPath: string): Promise<string[]> {
debugLog('Walking... ' + dirPath);

async function _walkAsync (dirPath: string): Promise<DeepList<string>> {
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);
Expand Down