Copy old macOS data directory if applicable

This commit is contained in:
Anmol Sethi
2020-05-14 06:08:37 -04:00
parent f475767c2b
commit 5651201643
3 changed files with 120 additions and 93 deletions

View File

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