fix(compile-cache): Write atomically to prevent process collisions

This commit is contained in:
Ben Gotow 2016-05-17 19:28:01 -07:00
parent 564d77421f
commit a46bcd1c34

View file

@ -102,8 +102,10 @@ function readCachedJavascript (relativeCachePath) {
} }
function writeCachedJavascript (relativeCachePath, code) { function writeCachedJavascript (relativeCachePath, code) {
var cacheTmpPath = path.join(cacheDirectory, relativeCachePath + '.' + process.pid)
var cachePath = path.join(cacheDirectory, relativeCachePath) var cachePath = path.join(cacheDirectory, relativeCachePath)
fs.writeFileSync(cachePath, code, 'utf8') fs.writeFileSync(cacheTmpPath, code, 'utf8')
fs.renameSync(cacheTmpPath, cachePath)
} }
function addSourceURL (jsCode, filePath) { function addSourceURL (jsCode, filePath) {