mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Removing temp file on error
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
87926c2498
commit
3d1fdff094
@ -24,16 +24,19 @@ import fs from "fs";
|
||||
import tempy from "tempy";
|
||||
import * as lockFile from "proper-lockfile";
|
||||
import YAML from "json-to-pretty-yaml";
|
||||
import { noop } from "../../utils";
|
||||
|
||||
export async function saveKubeconfig(config: KubeConfig, path: string) {
|
||||
const tmpFilePath = tempy.file();
|
||||
|
||||
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) => {
|
||||
}).catch(async (e) => {
|
||||
await fs.unlink(tmpFilePath, noop);
|
||||
throw new Error(`Failed to acquire lock file.\n${e}`);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user