From a4f3ae9f7fe29036cdbea0d48491ae8d106a359c Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 2 Aug 2023 21:57:44 -0700 Subject: make sure directory exists before downloading --- extension/src/activation/environmentSetup.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'extension') diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts index fd83c8ca..b25c7b82 100644 --- a/extension/src/activation/environmentSetup.ts +++ b/extension/src/activation/environmentSetup.ts @@ -105,6 +105,15 @@ async function checkOrKillRunningServer(serverUrl: string): Promise { return false; } +function ensureDirectoryExistence(filePath: string) { + const dirname = path.dirname(filePath); + if (fs.existsSync(dirname)) { + return true; + } + ensureDirectoryExistence(dirname); + fs.mkdirSync(dirname); +} + export async function downloadFromS3( bucket: string, fileName: string, @@ -122,6 +131,7 @@ export async function downloadFromS3( throw new Error(errText); } const buffer = await response.buffer(); + ensureDirectoryExistence(destination); fs.writeFileSync(destination, buffer); } -- cgit v1.2.3-70-g09d2