mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* Convert ReleaseChannel into an InitializableState Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix init timing for DefaultUpdateChannel Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make UserStore loading seperate from creation to fix initialization timing errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix overrides of UserStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix UserStore tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move userStoreFileMigration call to the init runnable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add global override for userStoreFileMigratiom Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name>
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
|
|
import fse from "fs-extra";
|
|
import path from "path";
|
|
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
|
import { isErrnoException } from "../utils";
|
|
import { getInjectable } from "@ogre-tools/injectable";
|
|
|
|
export type UserStoreFileNameMigration = () => Promise<void>;
|
|
|
|
const userStoreFileNameMigrationInjectable = getInjectable({
|
|
id: "user-store-file-name-migration",
|
|
instantiate: (di): UserStoreFileNameMigration => {
|
|
const userDataPath = di.inject(directoryForUserDataInjectable);
|
|
const configJsonPath = path.join(userDataPath, "config.json");
|
|
const lensUserStoreJsonPath = path.join(userDataPath, "lens-user-store.json");
|
|
|
|
return async () => {
|
|
try {
|
|
await fse.move(configJsonPath, lensUserStoreJsonPath);
|
|
} catch (error) {
|
|
if (error instanceof Error && error.message === "dest already exists.") {
|
|
await fse.remove(configJsonPath);
|
|
} else if (isErrnoException(error) && error.code === "ENOENT" && error.path === configJsonPath) {
|
|
// (No such file or directory)
|
|
return; // file already moved
|
|
} else {
|
|
// pass other errors along
|
|
throw error;
|
|
}
|
|
}
|
|
};
|
|
},
|
|
causesSideEffects: true,
|
|
});
|
|
|
|
export default userStoreFileNameMigrationInjectable;
|