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:
Asher
2019-03-12 11:12:50 -05:00
parent 0a9f5d8eee
commit e597d49912
9 changed files with 86 additions and 57 deletions

View File

@ -1,5 +1,5 @@
import { logger, field } from "@coder/logger";
import { ReadWriteConnection } from "@coder/protocol";
import { mkdirP, ReadWriteConnection } from "@coder/protocol";
import { Server, ServerOptions } from "@coder/protocol/src/node/server";
import * as express from "express";
//@ts-ignore
@ -20,7 +20,7 @@ import safeCompare = require("safe-compare");
import { TunnelCloseCode } from "@coder/tunnel/src/common";
import { handle as handleTunnel } from "@coder/tunnel/src/server";
import { createPortScanner } from "./portScanner";
import { buildDir, isCli } from "./constants";
import { buildDir } from "./constants";
interface CreateAppOptions {
registerMiddleware?: (app: express.Application) => void;
@ -257,8 +257,9 @@ export const createApp = async (options: CreateAppOptions): Promise<{
req.on("data", (chunk) => {
data.push(chunk);
});
req.on("end", () => {
req.on("end", async () => {
const body = data.join("");
await mkdirP(path.dirname(fullPath));
fs.writeFileSync(fullPath, body);
logger.debug("Wrote resource", field("path", fullPath), field("content-length", body.length));
res.status(200);