1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/migrations/user-store/file-name-migration.ts
Sebastian Malton 86815ae9f5 fix timing issue with fileNameMigration
Signed-off-by: Sebastian Malton <sebastian@malton.name>
2021-03-16 08:52:39 -04:00

23 lines
747 B
TypeScript

import fse from "fs-extra";
import { app, remote } from "electron";
import path from "path";
export async function fileNameMigration() {
const userDataPath = (app || remote.app).getPath("userData");
const configJsonPath = path.join(userDataPath, "config.json");
const lensUserStoreJsonPath = path.join(userDataPath, "lens-user-store.json");
try {
await fse.move(configJsonPath, lensUserStoreJsonPath);
} catch (error) {
if (error.code === "ENOENT" && error.path === configJsonPath) { // (No such file or directory)
return; // file already moved
} else if (error.message === "dest already exists.") {
await fse.remove(configJsonPath);
} else {
// pass other errors along
throw error;
}
}
}