mirror of
https://github.com/koush/scrypted.git
synced 2026-02-28 08:22:29 +00:00
postrelease
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user