diff --git a/src/common/user-store.ts b/src/common/user-store.ts index 97ba08f3cc..c7ad21f988 100644 --- a/src/common/user-store.ts +++ b/src/common/user-store.ts @@ -10,6 +10,7 @@ import { kubeConfigDefaultPath, loadConfig } from "./kube-helpers"; import { appEventBus } from "./event-bus"; import logger from "../main/logger"; import path from "path"; +import { fileNameMigration } from "../migrations/user-store"; export interface UserStoreModel { kubeConfigPath: string; @@ -37,7 +38,7 @@ export class UserStore extends BaseStore { private constructor() { super({ - // configName: "lens-user-store", // todo: migrate from default "config.json" + configName: "lens-user-store", migrations, }); @@ -85,6 +86,16 @@ export class UserStore extends BaseStore { } } + async load(): Promise { + /** + * This has to be here before the call to `new Config` in `super.load()` + * as we have to make sure that file is in the expected place for that call + */ + await fileNameMigration(); + + return super.load(); + } + get isNewVersion() { return semver.gt(getAppVersion(), this.lastSeenAppVersion); } diff --git a/src/migrations/user-store/file-name-migration.ts b/src/migrations/user-store/file-name-migration.ts new file mode 100644 index 0000000000..0abe6b280b --- /dev/null +++ b/src/migrations/user-store/file-name-migration.ts @@ -0,0 +1,22 @@ +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; + } + } +} diff --git a/src/migrations/user-store/index.ts b/src/migrations/user-store/index.ts index e1e7b8ffc9..5f5085b475 100644 --- a/src/migrations/user-store/index.ts +++ b/src/migrations/user-store/index.ts @@ -1,6 +1,11 @@ // User store migrations import version210Beta4 from "./2.1.0-beta.4"; +import { fileNameMigration } from "./file-name-migration"; + +export { + fileNameMigration +}; export default { ...version210Beta4,