Protect against races in deleting corrupt cache

Reviewed By: @cpojer

Differential Revision: D2426450
This commit is contained in:
Amjad Masad 2015-09-09 15:59:35 -07:00 committed by facebook-github-bot-6
parent 68fb275c78
commit c308774bc1
1 changed files with 5 additions and 1 deletions

View File

@ -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;