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;
|
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 * as os from "os";
|
||||||
import { logger, field } from "@coder/logger";
|
import { logger, field } from "@coder/logger";
|
||||||
import { Pong, ClientMessage, WorkingInitMessage, ServerMessage } from "../proto";
|
import { Pong, ClientMessage, WorkingInitMessage, ServerMessage } from "../proto";
|
||||||
import { evaluate, ActiveEvaluation } from "./evaluate";
|
import { evaluate, ActiveEvaluation } from "./evaluate";
|
||||||
import { ForkProvider } from "../common/helpers";
|
import { ForkProvider } from "../common/helpers";
|
||||||
import { ReadWriteConnection } from "../common/connection";
|
import { ReadWriteConnection } from "../common/connection";
|
||||||
import { mkdirP } from "../common/util";
|
|
||||||
|
|
||||||
export interface ServerOptions {
|
export interface ServerOptions {
|
||||||
readonly workingDirectory: string;
|
readonly workingDirectory: string;
|
||||||
@ -42,9 +42,9 @@ export class Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Promise.all([
|
Promise.all([
|
||||||
mkdirP(this.options.cacheDirectory),
|
mkdirp(this.options.cacheDirectory),
|
||||||
mkdirP(this.options.dataDirectory),
|
mkdirp(this.options.dataDirectory),
|
||||||
mkdirP(this.options.workingDirectory),
|
mkdirp(this.options.workingDirectory),
|
||||||
]).catch((error) => {
|
]).catch((error) => {
|
||||||
logger.error(error.message, field("error", 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 { field, logger } from "@coder/logger";
|
||||||
import { mkdirP } from "@coder/protocol";
|
|
||||||
import { ServerMessage, SharedProcessActiveMessage } from "@coder/protocol/src/proto";
|
import { ServerMessage, SharedProcessActiveMessage } from "@coder/protocol/src/proto";
|
||||||
import { Command, flags } from "@oclif/command";
|
import { Command, flags } from "@oclif/command";
|
||||||
import { fork, ForkOptions, ChildProcess } from "child_process";
|
import { fork, ForkOptions, ChildProcess } from "child_process";
|
||||||
@ -55,16 +55,15 @@ export class Entry extends Command {
|
|||||||
if (!fs.existsSync(dataDir)) {
|
if (!fs.existsSync(dataDir)) {
|
||||||
const oldDataDir = path.resolve(path.join(os.homedir(), ".code-server"));
|
const oldDataDir = path.resolve(path.join(os.homedir(), ".code-server"));
|
||||||
if (fs.existsSync(oldDataDir)) {
|
if (fs.existsSync(oldDataDir)) {
|
||||||
await mkdirP(path.basename(dataDir));
|
await fse.move(oldDataDir, dataDir);
|
||||||
fs.renameSync(oldDataDir, dataDir);
|
|
||||||
logger.info(`Moved data directory from ${oldDataDir} to ${dataDir}`);
|
logger.info(`Moved data directory from ${oldDataDir} to ${dataDir}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
mkdirP(cacheHome),
|
fse.mkdirp(cacheHome),
|
||||||
mkdirP(dataDir),
|
fse.mkdirp(dataDir),
|
||||||
mkdirP(workingDir),
|
fse.mkdirp(workingDir),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
setupNativeModules(dataDir);
|
setupNativeModules(dataDir);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
import { mkdirp } from "fs-extra";
|
||||||
import { logger, field } from "@coder/logger";
|
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 { Server, ServerOptions } from "@coder/protocol/src/node/server";
|
||||||
import * as express from "express";
|
import * as express from "express";
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
@ -259,7 +260,7 @@ export const createApp = async (options: CreateAppOptions): Promise<{
|
|||||||
});
|
});
|
||||||
req.on("end", async () => {
|
req.on("end", async () => {
|
||||||
const body = data.join("");
|
const body = data.join("");
|
||||||
await mkdirP(path.dirname(fullPath));
|
await mkdirp(path.dirname(fullPath));
|
||||||
fs.writeFileSync(fullPath, body);
|
fs.writeFileSync(fullPath, body);
|
||||||
logger.debug("Wrote resource", field("path", fullPath), field("content-length", body.length));
|
logger.debug("Wrote resource", field("path", fullPath), field("content-length", body.length));
|
||||||
res.status(200);
|
res.status(200);
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { readFile, writeFile } from "fs";
|
import { readFile, writeFile } from "fs";
|
||||||
|
import { mkdirp } from "fs-extra";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import { promisify } from "util";
|
import { promisify } from "util";
|
||||||
import { IDisposable } from "@coder/disposable";
|
import { IDisposable } from "@coder/disposable";
|
||||||
import { logger, field } from "@coder/logger";
|
import { logger, field } from "@coder/logger";
|
||||||
import { mkdirP } from "@coder/protocol";
|
|
||||||
import { Event } from "vs/base/common/event";
|
import { Event } from "vs/base/common/event";
|
||||||
import * as workspaceStorage from "vs/base/node/storage";
|
import * as workspaceStorage from "vs/base/node/storage";
|
||||||
import * as globalStorage from "vs/platform/storage/node/storageIpc";
|
import * as globalStorage from "vs/platform/storage/node/storageIpc";
|
||||||
@ -78,7 +78,7 @@ class StorageDatabase implements workspaceStorage.IStorageDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async save(): Promise<void> {
|
private async save(): Promise<void> {
|
||||||
await mkdirP(path.dirname(this.path));
|
await mkdirp(path.dirname(this.path));
|
||||||
|
|
||||||
return promisify(writeFile)(this.path, this.content);
|
return promisify(writeFile)(this.path, this.content);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user