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

Function downloadWithNet

src/launcher/fetcher.cpp:164–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162
163
164static Try<string> downloadWithNet(
165 const string& sourceUri,
166 const string& destinationPath,
167 const Option<Duration>& stallTimeout)
168{
169 // The net::download function only supports these protocols.
170 CHECK(strings::startsWith(sourceUri, "http://") ||
171 strings::startsWith(sourceUri, "https://") ||
172 strings::startsWith(sourceUri, "ftp://") ||
173 strings::startsWith(sourceUri, "ftps://"));
174
175 LOG(INFO) << "Downloading resource from '" << sourceUri
176 << "' to '" << destinationPath << "'";
177
178 Try<int> code = net::download(sourceUri, destinationPath, stallTimeout);
179 if (code.isError()) {
180 return Error("Error downloading resource: " + code.error());
181 } else {
182 // The status code for successful HTTP requests is 200, the status code
183 // for successful FTP file transfers is 226.
184 if (strings::startsWith(sourceUri, "ftp://") ||
185 strings::startsWith(sourceUri, "ftps://")) {
186 if (code.get() != 226) {
187 return Error("Error downloading resource, received FTP return code " +
188 stringify(code.get()));
189 }
190 } else {
191 if (code.get() != 200) {
192 return Error("Error downloading resource, received HTTP return code " +
193 stringify(code.get()));
194 }
195 }
196 }
197
198 return destinationPath;
199}
200
201
202// TODO(coffler): Refactor code to eliminate redundant function.

Callers 1

downloadFunction · 0.85

Calls 7

startsWithFunction · 0.85
downloadFunction · 0.70
errorMethod · 0.65
ErrorFunction · 0.50
stringifyFunction · 0.50
isErrorMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected