mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Use atomic write
This commit is contained in:
@ -5,6 +5,7 @@ const fetch = require('node-fetch').default;
|
|||||||
const sanitize = require('sanitize-filename');
|
const sanitize = require('sanitize-filename');
|
||||||
const { getConfigValue } = require('../util');
|
const { getConfigValue } = require('../util');
|
||||||
const { jsonParser } = require('../express-common');
|
const { jsonParser } = require('../express-common');
|
||||||
|
const writeFileAtomicSync = require('write-file-atomic').sync;
|
||||||
const contentDirectory = path.join(process.cwd(), 'default/content');
|
const contentDirectory = path.join(process.cwd(), 'default/content');
|
||||||
const contentIndexPath = path.join(contentDirectory, 'index.json');
|
const contentIndexPath = path.join(contentDirectory, 'index.json');
|
||||||
const characterCardParser = require('../character-card-parser.js');
|
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}`);
|
console.log(`Content file ${contentItem.filename} copied to ${contentTarget}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(contentLogPath, contentLog.join('\n'));
|
writeFileAtomicSync(contentLogPath, contentLog.join('\n'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const commandExistsSync = require('command-exists').sync;
|
const commandExistsSync = require('command-exists').sync;
|
||||||
|
const writeFileAtomicSync = require('write-file-atomic').sync;
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const yauzl = require('yauzl');
|
const yauzl = require('yauzl');
|
||||||
const mime = require('mime-types');
|
const mime = require('mime-types');
|
||||||
@ -61,7 +62,7 @@ function setConfigValue(key, value) {
|
|||||||
CACHED_CONFIG = null;
|
CACHED_CONFIG = null;
|
||||||
const config = getConfig();
|
const config = getConfig();
|
||||||
_.set(config, key, value);
|
_.set(config, key, value);
|
||||||
fs.writeFileSync('./config.yaml', yaml.stringify(config));
|
writeFileAtomicSync('./config.yaml', yaml.stringify(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user