We load the module manifests sequentially in an alphabetical order. If an error is encountered while processing a particular manifest, we do not load the remaining manifests and exit with the appropriate error message.
| 357 | // error is encountered while processing a particular manifest, we do not load |
| 358 | // the remaining manifests and exit with the appropriate error message. |
| 359 | Try<Nothing> ModuleManager::load(const string& modulesDir) |
| 360 | { |
| 361 | Try<list<string>> moduleManifests = os::ls(modulesDir); |
| 362 | if (moduleManifests.isError()) { |
| 363 | return Error( |
| 364 | "Error loading module manifests from '" + modulesDir + "' directory: " + |
| 365 | moduleManifests.error()); |
| 366 | } |
| 367 | |
| 368 | moduleManifests->sort(); |
| 369 | foreach (const string& filename, moduleManifests.get()) { |
| 370 | const string filepath = path::join(modulesDir, filename); |
| 371 | VLOG(1) << "Processing module manifest from '" << filepath << "'"; |
| 372 | |
| 373 | Try<string> read = os::read(filepath); |
| 374 | if (read.isError()) { |
| 375 | return Error( |
| 376 | "Error reading module manifest file '" + filepath + "': " + |
| 377 | read.error()); |
| 378 | } |
| 379 | |
| 380 | Try<Modules> modules = flags::parse<Modules>(read.get()); |
| 381 | if (modules.isError()) { |
| 382 | return Error( |
| 383 | "Error parsing module manifest file '" + filepath + "': " + |
| 384 | modules.error()); |
| 385 | } |
| 386 | |
| 387 | Try<Nothing> result = loadManifest(modules.get()); |
| 388 | if (result.isError()) { |
| 389 | return Error( |
| 390 | "Error loading modules from '" + filepath + "': " + result.error()); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | return Nothing(); |
| 395 | } |