|
|
|
@ -89,14 +89,18 @@ storage.crashSafeWriteFileLines = (filename, lines, callback = () => {}) => { |
|
|
|
|
}, |
|
|
|
|
cb => { |
|
|
|
|
try { |
|
|
|
|
const stream = fs.createWriteStream(tempFilename, { |
|
|
|
|
flags: 'w' |
|
|
|
|
}) |
|
|
|
|
for (const line of lines) { |
|
|
|
|
stream.write(line) |
|
|
|
|
stream.write('\n') |
|
|
|
|
const stream = fs.createWriteStream(tempFilename) |
|
|
|
|
const next = () => { |
|
|
|
|
const line = lines.shift() |
|
|
|
|
if (line === undefined) { |
|
|
|
|
stream.close(cb) |
|
|
|
|
} else { |
|
|
|
|
stream.write(line) |
|
|
|
|
stream.write('\n') |
|
|
|
|
setImmediate(next) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
stream.close(() => cb()) |
|
|
|
|
next() |
|
|
|
|
} catch (err) { |
|
|
|
|
cb(err) |
|
|
|
|
} |
|
|
|
|