写入文件增加文件锁,避免竞争条件引起文件内容异常

This commit is contained in:
whyour
2025-01-04 01:22:29 +08:00
parent 7d43b14f81
commit 05f8bbd26e
13 changed files with 103 additions and 55 deletions
+2 -1
View File
@@ -10,6 +10,7 @@ import { load } from 'js-yaml';
import config from './index';
import { TASK_COMMAND } from './const';
import Logger from '../loaders/logger';
import { writeFileWithLock } from '../shared/utils';
export * from './share';
@@ -170,7 +171,7 @@ export async function fileExist(file: any) {
export async function createFile(file: string, data: string = '') {
await fs.mkdir(path.dirname(file), { recursive: true });
await fs.writeFile(file, data);
await writeFileWithLock(file, data);
}
export async function handleLogPath(