Fix crash if populating packages in two processes

This commit is contained in:
David Glasser
2014-02-20 15:34:36 -08:00
parent 4d682e3a1c
commit 54074fdac7

View File

@@ -341,11 +341,24 @@ _.extend(warehouse, {
// (whether or not we just downloaded them). (Don't do this if we didn't
// print the installing message!)
if (newPieces && showInstalling) {
var unlinkIfExists = function (file) {
try {
fs.unlinkSync(file);
} catch (e) {
// If two processes populate the warehouse in parallel, the other
// process may have deleted the fresh file. That's OK!
if (e.code === "ENOENT")
return;
throw e;
}
};
if (newPieces.tools) {
fs.unlinkSync(warehouse.getToolsFreshFile(newPieces.tools.version));
unlinkIfExists(warehouse.getToolsFreshFile(newPieces.tools.version));
}
_.each(newPieces.packages, function (packageInfo, name) {
fs.unlinkSync(warehouse.getPackageFreshFile(name, packageInfo.version));
unlinkIfExists(
warehouse.getPackageFreshFile(name, packageInfo.version));
});
}