1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Releasing kubeconfig file after lock

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2021-08-22 16:26:56 +03:00 committed by Sebastian Malton
parent c9bf212153
commit fe12fde589

View File

@ -26,12 +26,13 @@ import * as lockFile from "proper-lockfile";
import YAML from "json-to-pretty-yaml";
export async function saveKubeconfig(config: KubeConfig, path: string) {
lockFile.lock(path).then(async () => {
lockFile.lock(path).then(async (release) => {
const tmpFilePath = tempy.file();
const contents = YAML.stringify(JSON.parse(config.exportConfig()));
await fs.promises.writeFile(tmpFilePath, contents);
await fs.promises.rename(tmpFilePath, path);
release();
}).catch((e) => {
throw new Error(`Failed to aquire lock file.\n${e}`);
});