|
1 | 1 | import { field, Level, logger } from "@coder/logger"
|
2 |
| -import * as fs from "fs-extra" |
| 2 | +import { promises as fs } from "fs" |
3 | 3 | import yaml from "js-yaml"
|
4 | 4 | import * as os from "os"
|
5 | 5 | import * as path from "path"
|
@@ -385,7 +385,6 @@ export async function setDefaults(cliArgs: Args, configArgs?: ConfigArgs): Promi
|
385 | 385 | const args = Object.assign({}, configArgs || {}, cliArgs)
|
386 | 386 |
|
387 | 387 | if (!args["user-data-dir"]) {
|
388 |
| - await copyOldMacOSDataDir() |
389 | 388 | args["user-data-dir"] = paths.data
|
390 | 389 | }
|
391 | 390 |
|
@@ -510,13 +509,20 @@ export async function readConfigFile(configPath?: string): Promise<ConfigArgs> {
|
510 | 509 | }
|
511 | 510 | }
|
512 | 511 |
|
513 |
| - if (!(await fs.pathExists(configPath))) { |
514 |
| - await fs.outputFile(configPath, await defaultConfigFile()) |
| 512 | + try { |
| 513 | + await fs.writeFile(configPath, await defaultConfigFile(), { |
| 514 | + flag: "wx", // wx means to fail if the path exists. |
| 515 | + }) |
515 | 516 | logger.info(`Wrote default config file to ${humanPath(configPath)}`)
|
| 517 | + } catch (error) { |
| 518 | + // EEXIST is fine; we don't want to overwrite existing configurations. |
| 519 | + if (error.code !== "EEXIST") { |
| 520 | + throw error |
| 521 | + } |
516 | 522 | }
|
517 | 523 |
|
518 |
| - const configFile = await fs.readFile(configPath) |
519 |
| - return parseConfigFile(configFile.toString(), configPath) |
| 524 | + const configFile = await fs.readFile(configPath, "utf8") |
| 525 | + return parseConfigFile(configFile, configPath) |
520 | 526 | }
|
521 | 527 |
|
522 | 528 | /**
|
@@ -599,21 +605,6 @@ function bindAddrFromAllSources(...argsConfig: Args[]): Addr {
|
599 | 605 | return addr
|
600 | 606 | }
|
601 | 607 |
|
602 |
| -async function copyOldMacOSDataDir(): Promise<void> { |
603 |
| - if (os.platform() !== "darwin") { |
604 |
| - return |
605 |
| - } |
606 |
| - if (await fs.pathExists(paths.data)) { |
607 |
| - return |
608 |
| - } |
609 |
| - |
610 |
| - // If the old data directory exists, we copy it in. |
611 |
| - const oldDataDir = path.join(os.homedir(), "Library/Application Support", "code-server") |
612 |
| - if (await fs.pathExists(oldDataDir)) { |
613 |
| - await fs.copy(oldDataDir, paths.data) |
614 |
| - } |
615 |
| -} |
616 |
| - |
617 | 608 | export const shouldRunVsCodeCli = (args: Args): boolean => {
|
618 | 609 | return !!args["list-extensions"] || !!args["install-extension"] || !!args["uninstall-extension"]
|
619 | 610 | }
|
|
0 commit comments