@ -200,47 +200,18 @@ export class UpdateHttpProvider extends HttpProvider {
|
||||
}
|
||||
logger.debug("Downloaded update", field("path", downloadPath))
|
||||
|
||||
// The archive should have a code-server directory at the top level.
|
||||
try {
|
||||
const stat = await fs.stat(path.join(downloadPath, "code-server"))
|
||||
if (!stat.isDirectory()) {
|
||||
throw new Error("ENOENT")
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error("no code-server directory found in downloaded archive")
|
||||
}
|
||||
// The archive should have a directory inside at the top level with the
|
||||
// same name as the archive.
|
||||
const directoryPath = path.join(downloadPath, path.basename(downloadPath))
|
||||
await fs.stat(directoryPath)
|
||||
|
||||
// The archive might contain a binary or it might contain loose files.
|
||||
// This is probably stupid but just check if `node` exists since we
|
||||
// package it with the loose files.
|
||||
const isBinary = !(await fs.pathExists(path.join(downloadPath, "code-server/node")))
|
||||
|
||||
// In the binary we need to replace the binary, otherwise we can replace
|
||||
// the directory.
|
||||
if (!targetPath) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
targetPath = (process.versions as any).nbin ? process.argv[0] : path.resolve(__dirname, "../../../")
|
||||
targetPath = path.resolve(__dirname, "../../../")
|
||||
}
|
||||
|
||||
// If we're currently running a binary it must be unlinked to avoid
|
||||
// ETXTBSY.
|
||||
try {
|
||||
const stat = await fs.stat(targetPath)
|
||||
if (stat.isFile()) {
|
||||
await fs.unlink(targetPath)
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.code !== "ENOENT") {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Replacing files", field("target", targetPath), field("isBinary", isBinary))
|
||||
if (isBinary) {
|
||||
await fs.move(path.join(downloadPath, "code-server/code-server"), targetPath, { overwrite: true })
|
||||
} else {
|
||||
await fs.move(path.join(downloadPath, "code-server"), targetPath, { overwrite: true })
|
||||
}
|
||||
logger.debug("Replacing files", field("target", targetPath))
|
||||
await fs.move(directoryPath, targetPath, { overwrite: true })
|
||||
|
||||
await fs.remove(downloadPath)
|
||||
|
||||
|
@ -13,9 +13,6 @@ import { generateCertificate, generatePassword, hash, open } from "./util"
|
||||
import { ipcMain, wrap } from "./wrapper"
|
||||
|
||||
const main = async (args: Args): Promise<void> => {
|
||||
// For any future forking bypass nbin and drop straight to Node.
|
||||
process.env.NBIN_BYPASS = "true"
|
||||
|
||||
const auth = args.auth || AuthType.Password
|
||||
const originalPassword = auth === AuthType.Password && (process.env.PASSWORD || (await generatePassword()))
|
||||
|
||||
@ -121,7 +118,6 @@ if (args.help) {
|
||||
}
|
||||
process.exit(0)
|
||||
} else if (args["list-extensions"] || args["install-extension"] || args["uninstall-extension"]) {
|
||||
process.env.NBIN_BYPASS = "true"
|
||||
logger.debug("forking vs code cli...")
|
||||
const vscode = cp.fork(path.resolve(__dirname, "../../lib/vscode/out/vs/server/fork"), [], {
|
||||
env: {
|
||||
|
@ -1,7 +1,5 @@
|
||||
import { logger, field } from "@coder/logger"
|
||||
import * as cp from "child_process"
|
||||
import * as fs from "fs-extra"
|
||||
import * as path from "path"
|
||||
import { Emitter } from "../common/emitter"
|
||||
|
||||
interface HandshakeMessage {
|
||||
@ -200,22 +198,12 @@ export class WrapperProcess {
|
||||
nodeOptions += ` --max_old_space_size=${(this.options && this.options.maxMemory) || 2048}`
|
||||
}
|
||||
|
||||
// This is to handle the upgrade from binary release to loose release. This
|
||||
// will only work for users that restart code-server entirely between
|
||||
// upgrading to this version and the loose file version since this is the
|
||||
// wrapper code that does not get updated. The hope is that it'll be likely
|
||||
// for that to happen to most users in that timeframe to minimize disruption
|
||||
// when loose files are release. This can be removed with that release.
|
||||
const bundledNodePath = path.join(process.argv[0], "node")
|
||||
const binary = (await fs.pathExists(bundledNodePath)) ? bundledNodePath : process.argv[0]
|
||||
|
||||
// Use spawn (instead of fork) to use the new binary in case it was updated.
|
||||
return cp.spawn(binary, process.argv.slice(1), {
|
||||
return cp.spawn(process.argv[0], process.argv.slice(1), {
|
||||
env: {
|
||||
...process.env,
|
||||
CODE_SERVER_PARENT_PID: process.pid.toString(),
|
||||
NODE_OPTIONS: nodeOptions,
|
||||
NBIN_BYPASS: undefined,
|
||||
},
|
||||
stdio: ["inherit", "inherit", "inherit", "ipc"],
|
||||
})
|
||||
|
Reference in New Issue
Block a user