From ea606de22f013a6c716aaf22aba3884cf08673ef Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Wed, 26 Jun 2024 09:43:48 -0700 Subject: [PATCH] postrelease --- server/package-lock.json | 4 +-- server/package.json | 2 +- .../src/plugin/runtime/node-worker-common.ts | 35 ++++++++++++++++--- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/server/package-lock.json b/server/package-lock.json index e4cdc66ca..28a1a8802 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/server", - "version": "0.113.0", + "version": "0.114.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@scrypted/server", - "version": "0.113.0", + "version": "0.114.0", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/server/package.json b/server/package.json index ba4c58203..683cc4d8f 100644 --- a/server/package.json +++ b/server/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/server", - "version": "0.114.0", + "version": "0.115.0", "description": "", "dependencies": { "@mapbox/node-pre-gyp": "^1.0.11", diff --git a/server/src/plugin/runtime/node-worker-common.ts b/server/src/plugin/runtime/node-worker-common.ts index 61d484a92..c65c1d1ab 100644 --- a/server/src/plugin/runtime/node-worker-common.ts +++ b/server/src/plugin/runtime/node-worker-common.ts @@ -15,6 +15,7 @@ function prep(pluginVolume: string, hash: string) { const zipFile = path.join(zipDir, zipFilename); const unzippedPath = path.join(zipDir, 'unzipped') const zipDirTmp = zipDir + '.tmp'; + const zipDirTmp2 = zipDir + '.tmp2'; return { unzippedPath, @@ -22,6 +23,7 @@ function prep(pluginVolume: string, hash: string) { zipDir, zipFile, zipDirTmp, + zipDirTmp2, }; } @@ -52,16 +54,39 @@ export function prepareZipSync(pluginVolume: string, h: string, getZip: () => Bu } export function extractZip(pluginVolume: string, h: string, zipBuffer: Buffer) { - const { zipDir, zipDirTmp, zipFilename, zipFile, unzippedPath } = prep(pluginVolume, h); + const { zipDir, zipDirTmp, zipDirTmp2, zipFilename, zipFile, unzippedPath } = prep(pluginVolume, h); + // stage the plugin zip in a tmp directory, then move it to the final location. + // so if the zip extraction is corrupt, it won't be used. fs.rmSync(zipDirTmp, { recursive: true, force: true, }); - fs.rmSync(zipDir, { - recursive: true, - force: true, - }); + + let zipDirTmp2Exists = false; + try { + fs.rmSync(zipDirTmp2, { + recursive: true, + force: true, + }); + } + catch (e) { + zipDirTmp2Exists = true; + } + + try { + fs.rmSync(zipDir, { + recursive: true, + force: true, + }); + } + catch (e) { + if (zipDirTmp2Exists) + throw e; + // file lock from dangling plugin process may have prevented the recursive rm from completing. + // try renaming it. it will get cleaned up eventually. + fs.renameSync(zipDir, zipDirTmp2); + } fs.mkdirSync(zipDirTmp, { recursive: true, });