diff --git a/package.json b/package.json index a6897714..12bd4916 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "patch:apply": "cd ../../../ && git apply ./src/vs/server/scripts/vscode.patch" }, "devDependencies": { - "@coder/nbin": "^1.2.2", + "@coder/nbin": "^1.2.3", "@types/fs-extra": "^8.0.1", "@types/node": "^10.12.12", "@types/pem": "^1.9.5", diff --git a/src/node/cli.ts b/src/node/cli.ts index ca96a9b9..5868672f 100644 --- a/src/node/cli.ts +++ b/src/node/cli.ts @@ -196,12 +196,14 @@ const startCli = (): boolean | Promise => { export class WrapperProcess { private process?: cp.ChildProcess; private started?: Promise; + private currentVersion = product.codeServerVersion; public constructor() { ipcMain.onMessage(async (message) => { - switch (message) { + switch (message.type) { case "relaunch": - logger.info("Relaunching..."); + logger.info(`Relaunching: ${this.currentVersion} -> ${message.version}`); + this.currentVersion = message.version; this.started = undefined; if (this.process) { this.process.removeAllListeners(); @@ -233,10 +235,16 @@ export class WrapperProcess { } private spawn(): cp.ChildProcess { - return cp.spawn(process.argv[0], process.argv.slice(1), { + // If we're using loose files then we need to specify the path. If we're in + // the binary we need to let the binary determine the path (via nbin) since + // it could be different between binaries which presents a problem when + // upgrading (different version numbers or different staging directories). + const isBinary = (global as any).NBIN_LOADED; + return cp.spawn(process.argv[0], process.argv.slice(isBinary ? 2 : 1), { env: { ...process.env, LAUNCH_VSCODE: "true", + NBIN_BYPASS: undefined, VSCODE_PARENT_PID: process.pid.toString(), }, stdio: ["inherit", "inherit", "inherit", "ipc"], diff --git a/src/node/ipc.ts b/src/node/ipc.ts index da188234..c92ea872 100644 --- a/src/node/ipc.ts +++ b/src/node/ipc.ts @@ -6,7 +6,12 @@ enum ControlMessage { okFromChild = "ok<", } -export type Message = "relaunch"; +interface RelaunchMessage { + type: "relaunch"; + version: string; +} + +export type Message = RelaunchMessage; class IpcMain { protected readonly _onMessage = new Emitter(); @@ -41,11 +46,15 @@ class IpcMain { }); } - public relaunch(): void { + public relaunch(version: string): void { + this.send({ type: "relaunch", version }); + } + + private send(message: Message): void { if (!process.send) { throw new Error("Not a child process with IPC enabled"); } - process.send("relaunch"); + process.send(message); } } diff --git a/src/node/update.ts b/src/node/update.ts index d85a22c7..878fe1b5 100644 --- a/src/node/update.ts +++ b/src/node/update.ts @@ -13,7 +13,7 @@ import { IFileService } from "vs/platform/files/common/files"; import { ILogService } from "vs/platform/log/common/log"; import product from "vs/platform/product/common/product"; import { asJson, IRequestService } from "vs/platform/request/common/request"; -import { AvailableForDownload, State, UpdateType } from "vs/platform/update/common/update"; +import { AvailableForDownload, State, UpdateType, StateType } from "vs/platform/update/common/update"; import { AbstractUpdateService } from "vs/platform/update/electron-main/abstractUpdateService"; import { ipcMain } from "vs/server/src/node/ipc"; import { extract } from "vs/server/src/node/marketplace"; @@ -62,7 +62,9 @@ export class UpdateService extends AbstractUpdateService { } public async doQuitAndInstall(): Promise { - ipcMain.relaunch(); + if (this.state.type === StateType.Ready) { + ipcMain.relaunch(this.state.update.version); + } } protected async doCheckForUpdates(context: any): Promise { diff --git a/yarn.lock b/yarn.lock index fdef4a1c..61205441 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7,10 +7,10 @@ resolved "https://registry.yarnpkg.com/@coder/logger/-/logger-1.1.8.tgz#416a7221d84161ee35eca9cfa93ba9377639b4ee" integrity sha512-NJDC4rZTx0deVYqAxZtJWACq3IrVR59BjFeZebO3i7OfTZZMkkbLsGsCFMnJd5KnX6KjnvvFq4XXtwJ9yf8/YQ== -"@coder/nbin@^1.2.2": - version "1.2.2" - resolved "https://registry.yarnpkg.com/@coder/nbin/-/nbin-1.2.2.tgz#c5f9aaa2a0e84c2a13a4cce895547efbd66730b7" - integrity sha512-1Z6aYBRZRY1AQ2xp0jmoz+TXR8M4WaHa9FfVkOPej0KPJjYtEp18I+/6CmffDtBLxSnIai0rc+AA0VhbjCN/rg== +"@coder/nbin@^1.2.3": + version "1.2.3" + resolved "https://registry.yarnpkg.com/@coder/nbin/-/nbin-1.2.3.tgz#793061abc7e1f7e0a9d1b9f854fa8f4121ed4e90" + integrity sha512-JGJhkaqCrAF9hQ8e7m29/gbbKqDrBAOJCdjNZv9LKF+67lmHUoJ2QS+eHN+KOtpO4EJeEs4/uq7LSEdT+g3t5w== dependencies: "@coder/logger" "^1.1.8" fs-extra "^7.0.1"