Skip to content

Commit b1a6dd4

Browse files
committed
Merge pull request atom#18134 from atom/revert-17774-fb-mdt-atomic-config-saves
Fix atom#18118 by reverting PR atom#17774: "Write config file atomically"
1 parent 5f459ce commit b1a6dd4

File tree

1 file changed

+5
-32
lines changed

1 file changed

+5
-32
lines changed

src/config-file.js

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const {watchPath} = require('./path-watcher')
66
const CSON = require('season')
77
const Path = require('path')
88
const async = require('async')
9-
const temp = require('temp')
109

1110
const EVENT_TYPES = new Set([
1211
'created',
@@ -38,20 +37,18 @@ class ConfigFile {
3837
this.reloadCallbacks = []
3938

4039
// Use a queue to prevent multiple concurrent write to the same file.
41-
const writeQueue = async.queue((data, callback) => {
42-
(async () => {
43-
try {
44-
await writeCSONFileAtomically(this.path, data)
45-
} catch (error) {
40+
const writeQueue = async.queue((data, callback) =>
41+
CSON.writeFile(this.path, data, error => {
42+
if (error) {
4643
this.emitter.emit('did-error', dedent `
4744
Failed to write \`${Path.basename(this.path)}\`.
4845
4946
${error.message}
5047
`)
5148
}
5249
callback()
53-
})()
54-
})
50+
})
51+
)
5552

5653
this.requestLoad = _.debounce(() => this.reload(), 200)
5754
this.requestSave = _.debounce((data) => writeQueue.push(data), 200)
@@ -119,27 +116,3 @@ class ConfigFile {
119116
})
120117
}
121118
}
122-
123-
function writeCSONFile (path, data) {
124-
return new Promise((resolve, reject) => {
125-
CSON.writeFile(path, data, error => {
126-
if (error) reject(error)
127-
else resolve()
128-
})
129-
})
130-
}
131-
132-
async function writeCSONFileAtomically (path, data) {
133-
const tempPath = temp.path()
134-
await writeCSONFile(tempPath, data)
135-
await rename(tempPath, path)
136-
}
137-
138-
function rename (oldPath, newPath) {
139-
return new Promise((resolve, reject) => {
140-
fs.rename(oldPath, newPath, error => {
141-
if (error) reject(error)
142-
else resolve()
143-
})
144-
})
145-
}

0 commit comments

Comments
 (0)