mirror of
https://github.com/atom/atom.git
synced 2026-01-25 23:08:18 -05:00
Merge pull request #18134 from atom/revert-17774-fb-mdt-atomic-config-saves
Fix #18118 by reverting PR #17774: "Write config file atomically"
This commit is contained in:
@@ -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()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user