From 59d5ebbe438c3eeaa6b6c9bc312dfdbc72278b60 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Fri, 18 Nov 2022 13:55:25 +0100 Subject: [PATCH] Only check pending directory on macOS --- .../sentry-minidump/minidump-loader.ts | 42 ++++++++----------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/src/main/integrations/sentry-minidump/minidump-loader.ts b/src/main/integrations/sentry-minidump/minidump-loader.ts index 30e4d1b25..deb89589e 100644 --- a/src/main/integrations/sentry-minidump/minidump-loader.ts +++ b/src/main/integrations/sentry-minidump/minidump-loader.ts @@ -86,12 +86,17 @@ async function deleteCrashpadMetadataFile(crashesDirectory: string, waitMs: numb } } -async function readDirAsyncIfExists(path: string): Promise { - try { - return await readDirAsync(path); - } catch (_) { - return []; +async function readDirsAsync(paths: string[]): Promise { + const found: string[] = []; + for (const path of paths) { + try { + const files = await readDirAsync(path); + found.push(...files.map((file) => join(path, file))); + } catch (_) { + // + } } + return found; } function crashpadMinidumpLoader(): MinidumpLoader { @@ -101,31 +106,20 @@ function crashpadMinidumpLoader(): MinidumpLoader { return createMinidumpLoader(async () => { await deleteCrashpadMetadataFile(crashesDirectory).catch((error) => logger.error(error)); - const dumpDirectory = join(crashesDirectory, crashpadSubDirectory); - const pendingDirectory = join(crashesDirectory, 'pending'); + const dumpDirectories = [join(crashesDirectory, crashpadSubDirectory)]; - return (await readDirAsyncIfExists(dumpDirectory)) - .filter((file) => file.endsWith('.dmp')) - .map((file) => { - const path = join(dumpDirectory, file); + if (process.platform === 'darwin') { + dumpDirectories.push(join(crashesDirectory, 'pending')); + } + return (await readDirsAsync(dumpDirectories)) + .filter((file) => file.endsWith('.dmp')) + .map((path) => { return { path, load: () => readFileAsync(path), }; - }) - .concat( - (await readDirAsyncIfExists(pendingDirectory)) - .filter((file) => file.endsWith('.dmp')) - .map((file) => { - const path = join(pendingDirectory, file); - - return { - path, - load: () => readFileAsync(path), - }; - }), - ); + }); }); }