mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
写入文件增加文件锁,避免竞争条件引起文件内容异常
This commit is contained in:
@@ -3,6 +3,7 @@ import path from 'path';
|
||||
import os from 'os';
|
||||
import Logger from './logger';
|
||||
import { fileExist } from '../config/util';
|
||||
import { writeFileWithLock } from '../shared/utils';
|
||||
|
||||
const rootPath = process.env.QL_DIR as string;
|
||||
let dataPath = path.join(rootPath, 'data/');
|
||||
@@ -99,46 +100,46 @@ export default async () => {
|
||||
// 初始化文件
|
||||
|
||||
if (!confFileExist) {
|
||||
await fs.writeFile(confFile, await fs.readFile(sampleConfigFile));
|
||||
await writeFileWithLock(confFile, await fs.readFile(sampleConfigFile));
|
||||
}
|
||||
|
||||
await fs.writeFile(jsNotifyFile, await fs.readFile(sampleNotifyJsFile));
|
||||
await fs.writeFile(pyNotifyFile, await fs.readFile(sampleNotifyPyFile));
|
||||
await writeFileWithLock(jsNotifyFile, await fs.readFile(sampleNotifyJsFile));
|
||||
await writeFileWithLock(pyNotifyFile, await fs.readFile(sampleNotifyPyFile));
|
||||
|
||||
if (!scriptNotifyJsFileExist) {
|
||||
await fs.writeFile(
|
||||
await writeFileWithLock(
|
||||
scriptNotifyJsFile,
|
||||
await fs.readFile(sampleNotifyJsFile),
|
||||
);
|
||||
}
|
||||
|
||||
if (!scriptNotifyPyFileExist) {
|
||||
await fs.writeFile(
|
||||
await writeFileWithLock(
|
||||
scriptNotifyPyFile,
|
||||
await fs.readFile(sampleNotifyPyFile),
|
||||
);
|
||||
}
|
||||
|
||||
if (!TaskBeforeFileExist) {
|
||||
await fs.writeFile(TaskBeforeFile, await fs.readFile(sampleTaskShellFile));
|
||||
await writeFileWithLock(TaskBeforeFile, await fs.readFile(sampleTaskShellFile));
|
||||
}
|
||||
|
||||
if (!TaskBeforeJsFileExist) {
|
||||
await fs.writeFile(
|
||||
await writeFileWithLock(
|
||||
TaskBeforeJsFile,
|
||||
'// The JavaScript code that executes before the JavaScript task execution will execute.',
|
||||
);
|
||||
}
|
||||
|
||||
if (!TaskBeforePyFileExist) {
|
||||
await fs.writeFile(
|
||||
await writeFileWithLock(
|
||||
TaskBeforePyFile,
|
||||
'# The Python code that executes before the Python task execution will execute.',
|
||||
);
|
||||
}
|
||||
|
||||
if (!TaskAfterFileExist) {
|
||||
await fs.writeFile(TaskAfterFile, await fs.readFile(sampleTaskShellFile));
|
||||
await writeFileWithLock(TaskAfterFile, await fs.readFile(sampleTaskShellFile));
|
||||
}
|
||||
|
||||
Logger.info('✌️ Init file down');
|
||||
|
||||
Reference in New Issue
Block a user