From c308774bc17c8193d7c2c61cc4cbe6cd8b7e48f0 Mon Sep 17 00:00:00 2001 From: Amjad Masad Date: Wed, 9 Sep 2015 15:59:35 -0700 Subject: [PATCH] Protect against races in deleting corrupt cache Reviewed By: @cpojer Differential Revision: D2426450 --- react-packager/src/lib/loadCacheSync.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/react-packager/src/lib/loadCacheSync.js b/react-packager/src/lib/loadCacheSync.js index 64188365..d04ec093 100644 --- a/react-packager/src/lib/loadCacheSync.js +++ b/react-packager/src/lib/loadCacheSync.js @@ -20,7 +20,11 @@ function loadCacheSync(cachePath) { } catch (e) { if (e instanceof SyntaxError) { console.warn('Unable to parse cache file. Will clear and continue.'); - fs.unlinkSync(cachePath); + try { + fs.unlinkSync(cachePath); + } catch (err) { + // Someone else might've deleted it. + } return Object.create(null); } throw e;