mirror of
https://github.com/coder/code-server.git
synced 2025-07-30 21:45:08 +08:00
Copy old macOS data directory if applicable
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { field, Level, logger } from "@coder/logger"
|
||||
import * as fs from "fs-extra"
|
||||
import yaml from "js-yaml"
|
||||
import * as os from "os"
|
||||
import * as path from "path"
|
||||
import { Args as VsArgs } from "../../lib/vscode/src/vs/server/ipc"
|
||||
import { AuthType } from "./http"
|
||||
@ -151,12 +152,12 @@ export const optionDescriptions = (): string[] => {
|
||||
)
|
||||
}
|
||||
|
||||
export const parse = (
|
||||
export const parse = async (
|
||||
argv: string[],
|
||||
opts?: {
|
||||
configFile: string
|
||||
},
|
||||
): Args => {
|
||||
): Promise<Args> => {
|
||||
const error = (msg: string): Error => {
|
||||
if (opts?.configFile) {
|
||||
msg = `error reading ${opts.configFile}: ${msg}`
|
||||
@ -300,6 +301,7 @@ export const parse = (
|
||||
}
|
||||
|
||||
if (!args["user-data-dir"]) {
|
||||
await copyOldMacOSDataDir()
|
||||
args["user-data-dir"] = paths.data
|
||||
}
|
||||
|
||||
@ -351,7 +353,7 @@ export async function readConfigFile(configPath?: string): Promise<Args> {
|
||||
}
|
||||
return `--${optName}=${opt}`
|
||||
})
|
||||
const args = parse(configFileArgv, {
|
||||
const args = await parse(configFileArgv, {
|
||||
configFile: configPath,
|
||||
})
|
||||
return {
|
||||
@ -400,3 +402,18 @@ export function bindAddrFromAllSources(cliArgs: Args, configArgs: Args): [string
|
||||
|
||||
return [addr.host, addr.port]
|
||||
}
|
||||
|
||||
async function copyOldMacOSDataDir(): Promise<void> {
|
||||
if (os.platform() !== "darwin") {
|
||||
return
|
||||
}
|
||||
if (await fs.pathExists(paths.data)) {
|
||||
return
|
||||
}
|
||||
|
||||
// If the old data directory exists, we copy it in.
|
||||
const oldDataDir = path.join(os.homedir(), "Library/Application Support", "code-server")
|
||||
if (await fs.pathExists(oldDataDir)) {
|
||||
await fs.copy(oldDataDir, paths.data)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user