Returns the resulting file or in case of extraction the destination directory (for logging).
| 404 | // Returns the resulting file or in case of extraction the destination |
| 405 | // directory (for logging). |
| 406 | static Try<string> fetchThroughCache( |
| 407 | const FetcherInfo::Item& item, |
| 408 | const Option<string>& cacheDirectory, |
| 409 | const string& sandboxDirectory, |
| 410 | const Option<string>& frameworksHome, |
| 411 | const Option<Duration>& stallTimeout) |
| 412 | { |
| 413 | if (cacheDirectory.isNone() || cacheDirectory->empty()) { |
| 414 | return Error("Cache directory not specified"); |
| 415 | } |
| 416 | |
| 417 | if (!item.has_cache_filename() || item.cache_filename().empty()) { |
| 418 | // This should never happen if this program is used by the Mesos |
| 419 | // slave and could then be a CHECK. But other uses are possible. |
| 420 | return Error("No cache file name for: " + item.uri().value()); |
| 421 | } |
| 422 | |
| 423 | CHECK_NE(FetcherInfo::Item::BYPASS_CACHE, item.action()) |
| 424 | << "Unexpected fetcher action selector"; |
| 425 | |
| 426 | CHECK(os::exists(cacheDirectory.get())) |
| 427 | << "Fetcher cache directory was expected to exist but was not found"; |
| 428 | |
| 429 | if (item.action() == FetcherInfo::Item::DOWNLOAD_AND_CACHE) { |
| 430 | const string cachePath = |
| 431 | path::join(cacheDirectory.get(), item.cache_filename()); |
| 432 | |
| 433 | if (!os::exists(cachePath)) { |
| 434 | Try<string> downloaded = download( |
| 435 | item.uri().value(), |
| 436 | cachePath, |
| 437 | frameworksHome, |
| 438 | stallTimeout); |
| 439 | |
| 440 | if (downloaded.isError()) { |
| 441 | return Error(downloaded.error()); |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | return fetchFromCache(item, cacheDirectory.get(), sandboxDirectory); |
| 447 | } |
| 448 | |
| 449 | |
| 450 | // Returns the resulting file or in case of extraction the destination |
no test coverage detected