Archived
1
0

Replace fs-extra with fs.promises

Remove the Mac directory copy instead of refactoring it since we've had
this for a long time now and I think it's safe to assume that users
running code-server on Mac don't have the old directory anymore.
This commit is contained in:
Asher
2021-03-15 16:15:24 -05:00
parent 3ef7cc7d03
commit 964ebe8d0a
9 changed files with 37 additions and 78 deletions

View File

@ -1,5 +1,5 @@
import { field, Level, logger } from "@coder/logger"
import * as fs from "fs-extra"
import { promises as fs } from "fs"
import yaml from "js-yaml"
import * as os from "os"
import * as path from "path"
@ -385,7 +385,6 @@ export async function setDefaults(cliArgs: Args, configArgs?: ConfigArgs): Promi
const args = Object.assign({}, configArgs || {}, cliArgs)
if (!args["user-data-dir"]) {
await copyOldMacOSDataDir()
args["user-data-dir"] = paths.data
}
@ -510,13 +509,22 @@ export async function readConfigFile(configPath?: string): Promise<ConfigArgs> {
}
}
if (!(await fs.pathExists(configPath))) {
await fs.outputFile(configPath, await defaultConfigFile())
await fs.mkdir(path.dirname(configPath), { recursive: true })
try {
await fs.writeFile(configPath, await defaultConfigFile(), {
flag: "wx", // wx means to fail if the path exists.
})
logger.info(`Wrote default config file to ${humanPath(configPath)}`)
} catch (error) {
// EEXIST is fine; we don't want to overwrite existing configurations.
if (error.code !== "EEXIST") {
throw error
}
}
const configFile = await fs.readFile(configPath)
return parseConfigFile(configFile.toString(), configPath)
const configFile = await fs.readFile(configPath, "utf8")
return parseConfigFile(configFile, configPath)
}
/**
@ -599,21 +607,6 @@ function bindAddrFromAllSources(...argsConfig: Args[]): Addr {
return addr
}
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)
}
}
export const shouldRunVsCodeCli = (args: Args): boolean => {
return !!args["list-extensions"] || !!args["install-extension"] || !!args["uninstall-extension"]
}