mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 23:30:41 +09:00
Use safe file writing pattern (#421)
Write new file contents to a temporary file and then rename over the target file to avoid data loss in the unlikely event there's an error writing the new file contents or the process is interrupted. Resolves #416.
This commit is contained in:
1 parent
9e7a7a602f
commit
e23d07e965
15 files changed
+94
-35
No files matched your search
@@ -2,6 +2,7 @@
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const libFileOps = require("@clusterio/lib/file_ops");
|
||||
const libPlugin = require("@clusterio/lib/plugin");
|
||||
const RateLimiter = require("@clusterio/lib/RateLimiter");
|
||||
|
||||
@@ -25,7 +26,7 @@ async function loadTechnologies(masterConfig, logger) {
|
||||
async function saveTechnologies(masterConfig, technologies, logger) {
|
||||
let filePath = path.join(masterConfig.get("master.database_directory"), "technologies.json");
|
||||
logger.verbose(`writing ${filePath}`);
|
||||
await fs.outputFile(filePath, JSON.stringify([...technologies.entries()], null, 4));
|
||||
await libFileOps.safeOutputFile(filePath, JSON.stringify([...technologies.entries()], null, 4));
|
||||
}
|
||||
|
||||
class MasterPlugin extends libPlugin.BaseMasterPlugin {
|
||||
|
||||
Reference in new issue
Block a user