|
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,22 @@ 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 | + await fs.mkdir(path.dirname(configPath), { recursive: true }) |
| 513 | + |
| 514 | + try { |
| 515 | + await fs.writeFile(configPath, await defaultConfigFile(), { |
| 516 | + flag: "wx", // wx means to fail if the path exists. |
| 517 | + }) |
515 | 518 | logger.info(`Wrote default config file to ${humanPath(configPath)}`)
|
| 519 | + } catch (error) { |
| 520 | + // EEXIST is fine; we don't want to overwrite existing configurations. |
| 521 | + if (error.code !== "EEXIST") { |
| 522 | + throw error |
| 523 | + } |
516 | 524 | }
|
517 | 525 |
|
518 |
| - const configFile = await fs.readFile(configPath) |
519 |
| - return parseConfigFile(configFile.toString(), configPath) |
| 526 | + const configFile = await fs.readFile(configPath, "utf8") |
| 527 | + return parseConfigFile(configFile, configPath) |
520 | 528 | }
|
521 | 529 |
|
522 | 530 | /**
|
@@ -599,21 +607,6 @@ function bindAddrFromAllSources(...argsConfig: Args[]): Addr {
|
599 | 607 | return addr
|
600 | 608 | }
|
601 | 609 |
|
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 | 610 | export const shouldRunVsCodeCli = (args: Args): boolean => {
|
618 | 611 | return !!args["list-extensions"] || !!args["install-extension"] || !!args["uninstall-extension"]
|
619 | 612 | }
|
|
0 commit comments