MCPcopy Create free account
hub / github.com/apache/mesos / fetchFromCache

Function fetchFromCache

src/launcher/fetcher.cpp:344–401  ·  view source on GitHub ↗

Returns the resulting file or in case of extraction the destination directory (for logging).

Source from the content-addressed store, hash-verified

342// Returns the resulting file or in case of extraction the destination
343// directory (for logging).
344static Try<string> fetchFromCache(
345 const FetcherInfo::Item& item,
346 const string& cacheDirectory,
347 const string& sandboxDirectory)
348{
349 LOG(INFO) << "Fetching URI '" << item.uri().value() << "' from cache";
350
351 if (item.uri().has_output_file()) {
352 string dirname = Path(item.uri().output_file()).dirname();
353 if (dirname != ".") {
354 Try<Nothing> result =
355 os::mkdir(path::join(sandboxDirectory, dirname), true);
356
357 if (result.isError()) {
358 return Error(
359 "Unable to create subdirectory " + dirname +
360 " in sandbox: " + result.error());
361 }
362 }
363 }
364
365 Try<string> outputFile = item.uri().has_output_file()
366 ? item.uri().output_file()
367 : Fetcher::basename(item.uri().value());
368
369 if (outputFile.isError()) {
370 return Error(outputFile.error());
371 }
372
373 string destinationPath = path::join(sandboxDirectory, outputFile.get());
374
375 // Non-empty cache filename is guaranteed by the callers of this function.
376 CHECK(!item.cache_filename().empty());
377
378 string sourcePath = path::join(cacheDirectory, item.cache_filename());
379
380 if (item.uri().executable()) {
381 Try<string> copied = copyFile(sourcePath, destinationPath);
382 if (copied.isError()) {
383 return Error(copied.error());
384 }
385
386 return chmodExecutable(copied.get());
387 } else if (item.uri().extract()) {
388 Try<bool> extracted = extract(sourcePath, sandboxDirectory);
389 if (extracted.isError()) {
390 return Error(extracted.error());
391 } else if (extracted.get()) {
392 return sandboxDirectory;
393 } else {
394 LOG(WARNING) << "Copying instead of extracting resource from URI with "
395 << "'extract' flag, because it does not seem to be an "
396 << "archive: " << item.uri().value();
397 }
398 }
399
400 return copyFile(sourcePath, destinationPath);
401}

Callers 1

fetchThroughCacheFunction · 0.85

Calls 14

PathClass · 0.85
copyFileFunction · 0.85
chmodExecutableFunction · 0.85
dirnameMethod · 0.80
extractFunction · 0.70
errorMethod · 0.65
mkdirFunction · 0.50
joinFunction · 0.50
ErrorFunction · 0.50
valueMethod · 0.45
isErrorMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected