From a46bcd1c34628f775a9cb22e19602dd23e140c0c Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Tue, 17 May 2016 19:28:01 -0700 Subject: [PATCH] fix(compile-cache): Write atomically to prevent process collisions --- src/compile-cache.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compile-cache.js b/src/compile-cache.js index 186d98b40..71343a72b 100644 --- a/src/compile-cache.js +++ b/src/compile-cache.js @@ -102,8 +102,10 @@ function readCachedJavascript (relativeCachePath) { } function writeCachedJavascript (relativeCachePath, code) { + var cacheTmpPath = path.join(cacheDirectory, relativeCachePath + '.' + process.pid) var cachePath = path.join(cacheDirectory, relativeCachePath) - fs.writeFileSync(cachePath, code, 'utf8') + fs.writeFileSync(cacheTmpPath, code, 'utf8') + fs.renameSync(cacheTmpPath, cachePath) } function addSourceURL (jsCode, filePath) {