diff --git a/src/endpoints/content-manager.js b/src/endpoints/content-manager.js index e6ce885cf..6764c9768 100644 --- a/src/endpoints/content-manager.js +++ b/src/endpoints/content-manager.js @@ -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')); } /** diff --git a/src/util.js b/src/util.js index 5d6bd5e12..31d134bb0 100644 --- a/src/util.js +++ b/src/util.js @@ -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)); } /**