Fix issues with configuration directories
- Move the old data directory if possible. - Fix extension path to not use a hard-coded path and instead use the data directory. - Create every part of the path during startup. - Create each path when a connection is made as well in case they are deleted while the server is running. - Create every part of the path before saving settings or writing a file using the resource endpoint.
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
import { field, logger } from "@coder/logger";
|
||||
import { mkdirP } from "@coder/protocol";
|
||||
import { ServerMessage, SharedProcessActiveMessage } from "@coder/protocol/src/proto";
|
||||
import { Command, flags } from "@oclif/command";
|
||||
import { fork, ForkOptions, ChildProcess } from "child_process";
|
||||
import { randomFillSync } from "crypto";
|
||||
import * as fs from "fs";
|
||||
import * as os from "os";
|
||||
import * as path from "path";
|
||||
import * as WebSocket from "ws";
|
||||
import { createApp } from "./server";
|
||||
@ -50,6 +52,20 @@ export class Entry extends Command {
|
||||
const dataDir = path.resolve(flags["data-dir"] || path.join(dataHome, "code-server"));
|
||||
const workingDir = path.resolve(args["workdir"]);
|
||||
|
||||
if (!fs.existsSync(dataDir)) {
|
||||
const oldDataDir = path.resolve(path.join(os.homedir(), ".code-server"));
|
||||
if (fs.existsSync(oldDataDir)) {
|
||||
fs.renameSync(oldDataDir, dataDir);
|
||||
logger.info(`Moved data directory from ${oldDataDir} to ${dataDir}`);
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
mkdirP(cacheHome),
|
||||
mkdirP(dataDir),
|
||||
mkdirP(workingDir),
|
||||
]);
|
||||
|
||||
setupNativeModules(dataDir);
|
||||
const builtInExtensionsDir = path.resolve(buildDir || path.join(__dirname, ".."), "build/extensions");
|
||||
if (flags["bootstrap-fork"]) {
|
||||
@ -74,14 +90,6 @@ export class Entry extends Command {
|
||||
return requireFork(modulePath, JSON.parse(flags.args!), builtInExtensionsDir);
|
||||
}
|
||||
|
||||
if (!fs.existsSync(dataDir)) {
|
||||
fs.mkdirSync(dataDir);
|
||||
}
|
||||
|
||||
if (!fs.existsSync(cacheHome)) {
|
||||
fs.mkdirSync(cacheHome);
|
||||
}
|
||||
|
||||
const logDir = path.join(cacheHome, "code-server/logs", new Date().toISOString().replace(/[-:.TZ]/g, ""));
|
||||
process.env.VSCODE_LOGS = logDir;
|
||||
|
||||
@ -173,6 +181,7 @@ export class Entry extends Command {
|
||||
builtInExtensionsDirectory: builtInExtensionsDir,
|
||||
dataDirectory: dataDir,
|
||||
workingDirectory: workingDir,
|
||||
cacheDirectory: cacheHome,
|
||||
fork: (modulePath: string, args: string[], options: ForkOptions): ChildProcess => {
|
||||
if (options && options.env && options.env.AMD_ENTRYPOINT) {
|
||||
return forkModule(options.env.AMD_ENTRYPOINT, args, options, dataDir);
|
||||
@ -188,11 +197,6 @@ export class Entry extends Command {
|
||||
} : undefined,
|
||||
});
|
||||
|
||||
if (!fs.existsSync(workingDir)) {
|
||||
logger.info("Creating working directory", field("working-dir", workingDir));
|
||||
fs.mkdirSync(workingDir);
|
||||
}
|
||||
|
||||
logger.info("Starting webserver...", field("host", flags.host), field("port", flags.port));
|
||||
app.server.listen(flags.port, flags.host);
|
||||
let clientId = 1;
|
||||
|
Reference in New Issue
Block a user