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

Function executeFileOperation

src/slave/containerizer/mesos/launch.cpp:487–559  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

485
486
487static Try<Nothing> executeFileOperation(const ContainerFileOperation& op)
488{
489 switch (op.operation()) {
490 case ContainerFileOperation::SYMLINK: {
491 Try<Nothing> result =
492 ::fs::symlink(op.symlink().source(), op.symlink().target());
493 if (result.isError()) {
494 return Error(
495 "Failed to link '" + op.symlink().source() + "' as '" +
496 op.symlink().target() + "': " + result.error());
497 }
498
499 return Nothing();
500 }
501
502 case ContainerFileOperation::MOUNT: {
503#ifdef __linux__
504 Try<Nothing> result = mountContainerFilesystem(op.mount());
505 if (result.isError()) {
506 return Error(
507 "Failed to mount '" + stringify(JSON::protobuf(op.mount())) +
508 "': " + result.error());
509 }
510
511 return Nothing();
512#else
513 return Error("Container mount is not supported on non-Linux systems");
514#endif // __linux__
515 }
516
517 case ContainerFileOperation::RENAME: {
518 Try<Nothing> result =
519 os::rename(op.rename().source(), op.rename().target());
520
521 // TODO(jpeach): We should only fall back to `mv` if the error
522 // is EXDEV, in which case a rename is a copy+unlink.
523 if (result.isError()) {
524 Option<int> status = os::spawn(
525 "mv", {"mv", "-f", op.rename().source(), op.rename().target()});
526
527 if (status.isNone()) {
528 return Error(
529 "Failed to rename '" + op.rename().source() + "' to '" +
530 op.rename().target() + "': spawn failed");
531 }
532
533 if (!WSUCCEEDED(status.get())) {
534 return Error(
535 "Failed to rename '" + op.rename().source() + "' to '" +
536 op.rename().target() + "': " + WSTRINGIFY(status.get()));
537 }
538
539 result = Nothing();
540 }
541
542 return Nothing();
543 }
544

Callers 1

foreachFunction · 0.85

Calls 15

NothingClass · 0.85
mountContainerFilesystemFunction · 0.85
protobufFunction · 0.85
WSUCCEEDEDFunction · 0.85
WSTRINGIFYFunction · 0.85
errorMethod · 0.65
symlinkFunction · 0.50
ErrorFunction · 0.50
stringifyFunction · 0.50
renameFunction · 0.50
spawnFunction · 0.50
mkdirFunction · 0.50

Tested by

no test coverage detected