(db, idName, parentDir, infoFilename, defaultInfo, schema, optionSchemaPrefix, courseInfo, logger, callback)
| 159 | } |
| 160 | |
| 161 | function loadInfoDB(db, idName, parentDir, infoFilename, defaultInfo, schema, optionSchemaPrefix, courseInfo, logger, callback) { |
| 162 | // `cache` is an object with which we can cache information derived from course info |
| 163 | // in between successive calls to `checkInfoValid` |
| 164 | const cache = {}; |
| 165 | fs.readdir(parentDir, function(err, files) { |
| 166 | if (ERR(err, callback)) return; |
| 167 | |
| 168 | async.each(files, function(dir, callback) { |
| 169 | var infoFile = path.join(parentDir, dir, infoFilename); |
| 170 | jsonLoad.readInfoJSON(infoFile, schema, function(err, info) { |
| 171 | if (err && err.code && err.path && (err.code === 'ENOTDIR') && err.path === infoFile) { |
| 172 | // In a previous version of this code, we'd pre-filter |
| 173 | // all files in the parent directory to remove anything |
| 174 | // that may have accidentally slipped in, like .DS_Store. |
| 175 | // However, that resulted in a huge number of system calls |
| 176 | // that got really slow for large directories. Now, we'll |
| 177 | // just blindly try to read a file from the directory and assume |
| 178 | // that if we see ENOTDIR, that means the directory was not |
| 179 | // in fact a directory. |
| 180 | callback(null); |
| 181 | return; |
| 182 | } |
| 183 | if (ERR(err, callback)) return; |
| 184 | jsonLoad.validateOptions(info, infoFile, optionSchemaPrefix, schemas, function(err, info) { |
| 185 | if (ERR(err, callback)) return; |
| 186 | info[idName] = dir; |
| 187 | info.directory = dir; |
| 188 | err = checkInfoValid(idName, info, infoFile, courseInfo, logger, cache); |
| 189 | if (ERR(err, callback)) return; |
| 190 | if (info.disabled) { |
| 191 | callback(null); |
| 192 | return; |
| 193 | } |
| 194 | info = _.defaults(info, defaultInfo); |
| 195 | db[dir] = info; |
| 196 | return callback(null); |
| 197 | }); |
| 198 | }); |
| 199 | }, function(err) { |
| 200 | if (ERR(err, callback)) return; |
| 201 | logger.debug('successfully loaded info from ' + parentDir + ', number of items = ' + _.size(db)); |
| 202 | callback(null); |
| 203 | }); |
| 204 | }); |
| 205 | } |
| 206 | |
| 207 | module.exports.loadFullCourse = function(courseDir, logger, callback) { |
| 208 | var course = { |
no test coverage detected