Use atomic write

This commit is contained in:
Cohee 2024-04-27 22:02:04 +03:00
parent 01ccc32274
commit cbedfa4664
2 changed files with 4 additions and 2 deletions

View File

@ -5,6 +5,7 @@ const fetch = require('node-fetch').default;
const sanitize = require('sanitize-filename');
const { getConfigValue } = require('../util');
const { jsonParser } = require('../express-common');
const writeFileAtomicSync = require('write-file-atomic').sync;
const contentDirectory = path.join(process.cwd(), 'default/content');
const contentIndexPath = path.join(contentDirectory, 'index.json');
const characterCardParser = require('../character-card-parser.js');
@ -133,7 +134,7 @@ async function seedContentForUser(contentIndex, directories, forceCategories) {
console.log(`Content file ${contentItem.filename} copied to ${contentTarget}`);
}
fs.writeFileSync(contentLogPath, contentLog.join('\n'));
writeFileAtomicSync(contentLogPath, contentLog.join('\n'));
}
/**

View File

@ -1,6 +1,7 @@
const path = require('path');
const fs = require('fs');
const commandExistsSync = require('command-exists').sync;
const writeFileAtomicSync = require('write-file-atomic').sync;
const _ = require('lodash');
const yauzl = require('yauzl');
const mime = require('mime-types');
@ -61,7 +62,7 @@ function setConfigValue(key, value) {
CACHED_CONFIG = null;
const config = getConfig();
_.set(config, key, value);
fs.writeFileSync('./config.yaml', yaml.stringify(config));
writeFileAtomicSync('./config.yaml', yaml.stringify(config));
}
/**