postrelease

This commit is contained in:
Koushik Dutta
2024-06-26 09:43:48 -07:00
parent 9fbff43120
commit ea606de22f
3 changed files with 33 additions and 8 deletions

View File

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