Fixed race condtion causing server to occasionally fail to start up

This commit is contained in:
Caleb James DeLisle 2017-12-19 18:21:29 +01:00
parent ff0e4bfe86
commit fe0030a0d6

View file

@ -35,11 +35,16 @@ const hashesFromPinFile = (pinFile, fileName) => {
module.exports.load = function (cb) {
nThen((waitFor) => {
Fs.readdir('./pins', waitFor((err, list) => {
if (err) { throw err; }
if (err) {
if (err.code === 'ENOENT') {
dirList = [];
return;
}
throw err;
}
dirList = list;
}));
}).nThen((waitFor) => {
fileList.splice(0, fileList.length);
dirList.forEach((f) => {
sema.take((returnAfter) => {
Fs.readdir('./pins/' + f, waitFor(returnAfter((err, list2) => {