From 72f4a68d139e8265e7862e2f5813bca276bd8600 Mon Sep 17 00:00:00 2001 From: Jason Rudolph Date: Thu, 27 Sep 2018 18:33:09 -0400 Subject: [PATCH] Revert "Write config file atomically" --- src/config-file.js | 37 +++++-------------------------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/src/config-file.js b/src/config-file.js index f8cba37ef..35f3b5c38 100644 --- a/src/config-file.js +++ b/src/config-file.js @@ -6,7 +6,6 @@ const {watchPath} = require('./path-watcher') const CSON = require('season') const Path = require('path') const async = require('async') -const temp = require('temp') const EVENT_TYPES = new Set([ 'created', @@ -38,11 +37,9 @@ class ConfigFile { this.reloadCallbacks = [] // Use a queue to prevent multiple concurrent write to the same file. - const writeQueue = async.queue((data, callback) => { - (async () => { - try { - await writeCSONFileAtomically(this.path, data) - } catch (error) { + const writeQueue = async.queue((data, callback) => + CSON.writeFile(this.path, data, error => { + if (error) { this.emitter.emit('did-error', dedent ` Failed to write \`${Path.basename(this.path)}\`. @@ -50,8 +47,8 @@ class ConfigFile { `) } callback() - })() - }) + }) + ) this.requestLoad = _.debounce(() => this.reload(), 200) this.requestSave = _.debounce((data) => writeQueue.push(data), 200) @@ -119,27 +116,3 @@ class ConfigFile { }) } } - -function writeCSONFile (path, data) { - return new Promise((resolve, reject) => { - CSON.writeFile(path, data, error => { - if (error) reject(error) - else resolve() - }) - }) -} - -async function writeCSONFileAtomically (path, data) { - const tempPath = temp.path() - await writeCSONFile(tempPath, data) - await rename(tempPath, path) -} - -function rename (oldPath, newPath) { - return new Promise((resolve, reject) => { - fs.rename(oldPath, newPath, error => { - if (error) reject(error) - else resolve() - }) - }) -}