mirror of https://git.tuxpa.in/a/code-server.git
Fix moving data directory across devices
This commit is contained in:
parent
ba37a34fa2
commit
f7c1ebf667
|
@ -97,22 +97,3 @@ export const parse = (arg: string): any => { // tslint:disable-line no-any
|
|||
|
||||
return arg ? convert(JSON.parse(arg)) : arg;
|
||||
};
|
||||
|
||||
export const mkdirP = async (path: string): Promise<void> => {
|
||||
// Since our fills require this file, we can't import them up top or we get
|
||||
// circular dependency issue.
|
||||
const { mkdir } = require("fs") as typeof import("fs");
|
||||
const { promisify } = require("util") as typeof import("util");
|
||||
const split = path.replace(/^\/*|\/*$/g, "").split("/");
|
||||
let dir = "";
|
||||
while (split.length > 0) {
|
||||
dir += "/" + split.shift();
|
||||
try {
|
||||
await promisify(mkdir)(dir);
|
||||
} catch (error) {
|
||||
if (error.code !== "EEXIST" && error.code !== "EISDIR") {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { mkdirp } from "fs-extra";
|
||||
import * as os from "os";
|
||||
import { logger, field } from "@coder/logger";
|
||||
import { Pong, ClientMessage, WorkingInitMessage, ServerMessage } from "../proto";
|
||||
import { evaluate, ActiveEvaluation } from "./evaluate";
|
||||
import { ForkProvider } from "../common/helpers";
|
||||
import { ReadWriteConnection } from "../common/connection";
|
||||
import { mkdirP } from "../common/util";
|
||||
|
||||
export interface ServerOptions {
|
||||
readonly workingDirectory: string;
|
||||
|
@ -42,9 +42,9 @@ export class Server {
|
|||
}
|
||||
|
||||
Promise.all([
|
||||
mkdirP(this.options.cacheDirectory),
|
||||
mkdirP(this.options.dataDirectory),
|
||||
mkdirP(this.options.workingDirectory),
|
||||
mkdirp(this.options.cacheDirectory),
|
||||
mkdirp(this.options.dataDirectory),
|
||||
mkdirp(this.options.workingDirectory),
|
||||
]).catch((error) => {
|
||||
logger.error(error.message, field("error", error));
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as fse from "fs-extra";
|
||||
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";
|
||||
|
@ -55,16 +55,15 @@ export class Entry extends Command {
|
|||
if (!fs.existsSync(dataDir)) {
|
||||
const oldDataDir = path.resolve(path.join(os.homedir(), ".code-server"));
|
||||
if (fs.existsSync(oldDataDir)) {
|
||||
await mkdirP(path.basename(dataDir));
|
||||
fs.renameSync(oldDataDir, dataDir);
|
||||
await fse.move(oldDataDir, dataDir);
|
||||
logger.info(`Moved data directory from ${oldDataDir} to ${dataDir}`);
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
mkdirP(cacheHome),
|
||||
mkdirP(dataDir),
|
||||
mkdirP(workingDir),
|
||||
fse.mkdirp(cacheHome),
|
||||
fse.mkdirp(dataDir),
|
||||
fse.mkdirp(workingDir),
|
||||
]);
|
||||
|
||||
setupNativeModules(dataDir);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { mkdirp } from "fs-extra";
|
||||
import { logger, field } from "@coder/logger";
|
||||
import { mkdirP, ReadWriteConnection } from "@coder/protocol";
|
||||
import { ReadWriteConnection } from "@coder/protocol";
|
||||
import { Server, ServerOptions } from "@coder/protocol/src/node/server";
|
||||
import * as express from "express";
|
||||
//@ts-ignore
|
||||
|
@ -259,7 +260,7 @@ export const createApp = async (options: CreateAppOptions): Promise<{
|
|||
});
|
||||
req.on("end", async () => {
|
||||
const body = data.join("");
|
||||
await mkdirP(path.dirname(fullPath));
|
||||
await mkdirp(path.dirname(fullPath));
|
||||
fs.writeFileSync(fullPath, body);
|
||||
logger.debug("Wrote resource", field("path", fullPath), field("content-length", body.length));
|
||||
res.status(200);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { readFile, writeFile } from "fs";
|
||||
import { mkdirp } from "fs-extra";
|
||||
import * as path from "path";
|
||||
import { promisify } from "util";
|
||||
import { IDisposable } from "@coder/disposable";
|
||||
import { logger, field } from "@coder/logger";
|
||||
import { mkdirP } from "@coder/protocol";
|
||||
import { Event } from "vs/base/common/event";
|
||||
import * as workspaceStorage from "vs/base/node/storage";
|
||||
import * as globalStorage from "vs/platform/storage/node/storageIpc";
|
||||
|
@ -78,7 +78,7 @@ class StorageDatabase implements workspaceStorage.IStorageDatabase {
|
|||
}
|
||||
|
||||
private async save(): Promise<void> {
|
||||
await mkdirP(path.dirname(this.path));
|
||||
await mkdirp(path.dirname(this.path));
|
||||
|
||||
return promisify(writeFile)(this.path, this.content);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue