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

Method fetch

src/uri/fetchers/copy.cpp:77–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75
76
77Future<Nothing> CopyFetcherPlugin::fetch(
78 const URI& uri,
79 const string& directory,
80 const Option<string>& data,
81 const Option<string>& outputFileName) const
82{
83 // TODO(jojy): Validate the given URI.
84
85 if (!uri.has_path()) {
86 return Failure("URI path is not specified");
87 }
88
89 // TODO(jojy): Verify that the path is a file.
90
91 Try<Nothing> mkdir = os::mkdir(directory);
92 if (mkdir.isError()) {
93 return Failure(
94 "Failed to create directory '" +
95 directory + "': " + mkdir.error());
96 }
97
98 VLOG(1) << "Copying '" << uri.path() << "' to '" << directory << "'";
99
100#ifndef __WINDOWS__
101 const char* copyCommand = "cp";
102 const vector<string> argv = {"cp", "-a", uri.path(), directory};
103#else // __WINDOWS__
104 const char* copyCommand = os::Shell::name;
105 const vector<string> argv =
106 {os::Shell::arg0, os::Shell::arg1, "copy", "/Y", uri.path(), directory};
107#endif // __WINDOWS__
108
109 Try<Subprocess> s = subprocess(
110 copyCommand,
111 argv,
112 Subprocess::PATH(os::DEV_NULL),
113 Subprocess::PIPE(),
114 Subprocess::PIPE());
115
116 if (s.isError()) {
117 return Failure("Failed to exec the copy subprocess: " + s.error());
118 }
119
120 return await(
121 s->status(),
122 io::read(s->out().get()),
123 io::read(s->err().get()))
124 .then([](const tuple<
125 Future<Option<int>>,
126 Future<string>,
127 Future<string>>& t) -> Future<Nothing> {
128 const Future<Option<int>>& status = std::get<0>(t);
129 if (!status.isReady()) {
130 return Failure(
131 "Failed to get the exit status of the copy subprocess: " +
132 (status.isFailed() ? status.failure() : "discarded"));
133 }
134

Callers

nothing calls this directly

Calls 15

FailureClass · 0.85
NothingClass · 0.85
outMethod · 0.80
errMethod · 0.80
isReadyMethod · 0.80
isFailedMethod · 0.80
failureMethod · 0.80
errorMethod · 0.65
mkdirFunction · 0.50
subprocessFunction · 0.50
awaitFunction · 0.50
readFunction · 0.50

Tested by

no test coverage detected