From 34e2527306f64d54958f085a9cbdbb0df8a0bb72 Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 30 Oct 2024 08:57:28 +0100 Subject: [PATCH] fix: apply code review suggestions --- .../zwave-js/src/lib/driver/UpdateConfig.ts | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/zwave-js/src/lib/driver/UpdateConfig.ts b/packages/zwave-js/src/lib/driver/UpdateConfig.ts index 6356c242765d..d242da13b5bb 100644 --- a/packages/zwave-js/src/lib/driver/UpdateConfig.ts +++ b/packages/zwave-js/src/lib/driver/UpdateConfig.ts @@ -199,16 +199,30 @@ export async function installConfigUpdateInDocker( }; // Download tarball to a temporary directory - const tmpDir = path.join(os.tmpdir(), "zjs-config-update"); - const tarFilename = path.join(tmpDir, "zjs-config-update.tgz"); + let tmpDir: string; + try { + tmpDir = await fs.mkdtemp( + path.join(os.tmpdir(), "zjs-config-update-"), + ); + } catch (e) { + await freeLock(); + throw new ZWaveError( + `Config update failed: Could not create temporary directory. Reason: ${ + getErrorMessage( + e, + ) + }`, + ZWaveErrorCodes.Config_Update_InstallFailed, + ); + } + const tarFilename = path.join(tmpDir, "zjs-config-update.tgz"); const configModuleDir = path.dirname( require.resolve("@zwave-js/config/package.json"), ); const extractedDir = path.join(tmpDir, "extracted"); try { - await fs.mkdir(tmpDir, { recursive: true }); const handle = await fs.open(tarFilename, "w"); const fstream = handle.createWriteStream({ autoClose: true }); const response = got.stream.get(url);