Skip to content

Commit

Permalink
postrelease
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Jun 26, 2024
1 parent 9fbff43 commit ea606de
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
4 changes: 2 additions & 2 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scrypted/server",
"version": "0.114.0",
"version": "0.115.0",
"description": "",
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.11",
Expand Down
35 changes: 30 additions & 5 deletions server/src/plugin/runtime/node-worker-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ 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,
zipFilename,
zipDir,
zipFile,
zipDirTmp,
zipDirTmp2,
};
}

Expand Down Expand Up @@ -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,
});
Expand Down

0 comments on commit ea606de

Please sign in to comment.