From 93fa7341624e4735abcdf95811e47d79413a3822 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Wed, 27 Feb 2019 14:33:25 -0800 Subject: [PATCH] Don't crash if someone created a folder while we were checking to see if it exists --- src/compiler/sys.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 33283c93803..6d8c4628092 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -615,7 +615,17 @@ namespace ts { directoryExists, createDirectory(directoryName: string) { if (!nodeSystem.directoryExists(directoryName)) { - _fs.mkdirSync(directoryName); + // Wrapped in a try-catch to prevent crashing if we are in a race + // with another copy of ourselves to create the same directory + try { + _fs.mkdirSync(directoryName); + } + catch (e) { + if (e.code !== "EEXIST") { + // Failed for some other reason (access denied?); still throw + throw e; + } + } } }, getExecutingFilePath() {