From 77d9a8e1f6aa357198caace29fbfbf3d570ccc97 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Wed, 23 Feb 2022 15:53:47 -0700 Subject: [PATCH] cherry-pick(#12323): fix: tolerate EBUSY error when removing output directories (#12324) SHA: 71edad327b7bd07bf00eea510a1edd5e258048bf - Previous attempt: https://github.com/microsoft/playwright/pull/12300 - Revert with reasoning: https://github.com/aslushnikov/playwright/commit/ebc52d10e4ddc846b142a0e233934dd6fc2676dc Fixes #12106 --- packages/playwright-test/src/runner.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/playwright-test/src/runner.ts b/packages/playwright-test/src/runner.ts index 17dcd19a1f..64c0263b7d 100644 --- a/packages/playwright-test/src/runner.ts +++ b/packages/playwright-test/src/runner.ts @@ -352,7 +352,17 @@ export class Runner { // 12. Remove output directores. try { - await Promise.all(Array.from(outputDirs).map(outputDir => removeFolderAsync(outputDir))); + await Promise.all(Array.from(outputDirs).map(outputDir => removeFolderAsync(outputDir).catch(async error => { + if ((error as any).code === 'EBUSY') { + // We failed to remove folder, might be due to the whole folder being mounted inside a container: + // https://github.com/microsoft/playwright/issues/12106 + // Do a best-effort to remove all files inside of it instead. + const entries = await readDirAsync(outputDir).catch(e => []); + await Promise.all(entries.map(entry => removeFolderAsync(path.join(outputDir, entry)))); + } else { + throw error; + } + }))); } catch (e) { this._reporter.onError?.(serializeError(e)); return { status: 'failed' };