From 2ef5d17157fea27a8dec73c65fb88abd834e36b6 Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Mon, 28 Sep 2026 20:35:59 -0400 Subject: [PATCH 1/2] do not overwrite extensions if malformed --- src/distribution.ts | 31 ++++++++++++++++++------------- src/sync/git.ts | 8 +++----- src/sync/zip.ts | 8 +++----- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/distribution.ts b/src/distribution.ts index faa1e32..9bde1f0 100644 --- a/src/distribution.ts +++ b/src/distribution.ts @@ -133,16 +133,19 @@ ${json.slice(0, -2)} : undefined; } - public updateExtensions(): void { // we cannot handle enable/disable at the moment, see - if(!files.isDirectory(this.Extensions) || !files.isFile(this.extensions)) return; - - const json: string = fs.readFileSync(this.extensions, "utf-8"); - - const extensions: [{ + public updateExtensions(json: string): void { // we cannot handle enable/disable at the moment, see + const extensions: { identifier: string, version: string, enabled: boolean - }] = isValidJson(json) ? JSON.parse(json) : []; + }[] | undefined = isValidJson(json) ? JSON.parse(json) : undefined; + + if(!Array.isArray(extensions) || !extensions.every(e => isNotNull(e) && typeof e.identifier === "string" && e.identifier.trim() !== "")) + return logger.warn("Skipped updating extensions: extensions.json is malformed", true); + + fs.writeFileSync(this.extensions, json, {encoding: "utf-8"}); + + if(!files.isDirectory(this.Extensions)) return; const installed: string[] = fs.readdirSync(this.Extensions!, {withFileTypes: true}) .filter(f => f.isDirectory()) @@ -152,8 +155,10 @@ ${json.slice(0, -2)} for(const extension of extensions.filter(e => e.enabled)){ // check remote extensions if(isNotNull(vscode.extensions.getExtension(extension.identifier))) continue; // extension exists and is enabled - vscode.commands.executeCommand("workbench.extensions.installExtension", extension.identifier); - logger.info(`${logger.check} Installed ${extension.identifier}`); + vscode.commands.executeCommand("workbench.extensions.installExtension", extension.identifier).then( + () => logger.info(`${logger.check} Installed ${extension.identifier}`), + (error: any) => logger.warn(`Failed to install ${extension.identifier}: ${error?.message ?? error}`) + ); } // compare installed with remote @@ -178,10 +183,10 @@ ${json.slice(0, -2)} continue OUTER; // extension exists on remote // not found on remote, uninstall this extension - try{ - vscode.commands.executeCommand("workbench.extensions.uninstallExtension", identifier); - }finally{} // ignore failed uninstall (already uninstalled) - logger.info(`${logger.x} Uninstalled ${identifier}`); + vscode.commands.executeCommand("workbench.extensions.uninstallExtension", identifier).then( + () => logger.info(`${logger.x} Uninstalled ${identifier}`), + (error: any) => logger.debug(`Failed to uninstall ${identifier}: ${error?.message ?? error}`) // ignore failed uninstall (already uninstalled) + ); } } diff --git a/src/sync/git.ts b/src/sync/git.ts index 8d45ee7..3455f69 100644 --- a/src/sync/git.ts +++ b/src/sync/git.ts @@ -102,11 +102,9 @@ export const pull: (repo: string, branch?: string, skipNotify?: boolean) => Prom /* extensions */ { const extensions: string = path.join(temp, "extensions.json"); - if(files.isFile(extensions)){ - fs.copyFileSync(extensions, dist.extensions); - - dist.updateExtensions(); - }else + if(files.isFile(extensions)) + dist.updateExtensions(fs.readFileSync(extensions, {encoding: "utf-8"})); + else logger.warn("Extensions not found"); } diff --git a/src/sync/zip.ts b/src/sync/zip.ts index 2404639..6998b45 100644 --- a/src/sync/zip.ts +++ b/src/sync/zip.ts @@ -39,11 +39,9 @@ export const inport: (fsPath: string) => void = (fsPath: string) => { /* extensions */ { const extensions: AdmZip.IZipEntry | null = zip.getEntry("extensions.json"); - if(extensions && !extensions.isDirectory){ - zip.extractEntryTo("extensions.json", dist.User, undefined, true); - - dist.updateExtensions(); - }else + if(extensions && !extensions.isDirectory) + dist.updateExtensions(extensions.getData().toString("utf-8")); + else logger.warn("Extensions not found"); } From 6dc1b34f64b9d7918c8aa7cb244d46aebfca4463 Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Tue, 29 Sep 2026 21:26:35 -0400 Subject: [PATCH 2/2] rev logging change --- src/distribution.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/distribution.ts b/src/distribution.ts index 9bde1f0..5b6b6fe 100644 --- a/src/distribution.ts +++ b/src/distribution.ts @@ -155,10 +155,8 @@ ${json.slice(0, -2)} for(const extension of extensions.filter(e => e.enabled)){ // check remote extensions if(isNotNull(vscode.extensions.getExtension(extension.identifier))) continue; // extension exists and is enabled - vscode.commands.executeCommand("workbench.extensions.installExtension", extension.identifier).then( - () => logger.info(`${logger.check} Installed ${extension.identifier}`), - (error: any) => logger.warn(`Failed to install ${extension.identifier}: ${error?.message ?? error}`) - ); + vscode.commands.executeCommand("workbench.extensions.installExtension", extension.identifier); + logger.info(`${logger.check} Installed ${extension.identifier}`); } // compare installed with remote @@ -183,10 +181,10 @@ ${json.slice(0, -2)} continue OUTER; // extension exists on remote // not found on remote, uninstall this extension - vscode.commands.executeCommand("workbench.extensions.uninstallExtension", identifier).then( - () => logger.info(`${logger.x} Uninstalled ${identifier}`), - (error: any) => logger.debug(`Failed to uninstall ${identifier}: ${error?.message ?? error}`) // ignore failed uninstall (already uninstalled) - ); + try{ + vscode.commands.executeCommand("workbench.extensions.uninstallExtension", identifier); + }finally{} // ignore failed uninstall (already uninstalled) + logger.info(`${logger.x} Uninstalled ${identifier}`); } }