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

Method fetch

src/uri/fetchers/curl.cpp:90–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88
89
90Future<Nothing> CurlFetcherPlugin::fetch(
91 const URI& uri,
92 const string& directory,
93 const Option<string>& data,
94 const Option<string>& outputFileName) const
95{
96 // TODO(jieyu): Validate the given URI.
97
98 if (!uri.has_path()) {
99 return Failure("URI path is not specified");
100 }
101
102 Try<Nothing> mkdir = os::mkdir(directory);
103 if (mkdir.isError()) {
104 return Failure(
105 "Failed to create directory '" +
106 directory + "': " + mkdir.error());
107 }
108
109 string output;
110 if (outputFileName.isSome()) {
111 output = path::join(directory, outputFileName.get());
112 } else {
113 output = path::join(directory, Path(path::from_uri(uri.path())).basename());
114 }
115
116#ifndef __WINDOWS__
117 const string curl = "curl";
118#else
119 const string curl = "curl.exe";
120#endif // __WINDOWS__
121
122 vector<string> argv = {
123 curl,
124 "-s", // Don't show progress meter or error messages.
125 "-S", // Makes curl show an error message if it fails.
126 "-L", // Follow HTTP 3xx redirects.
127 "-w", "%{http_code}", // Display HTTP response code on stdout.
128 "-o", output, // Write output to the file.
129 strings::trim(stringify(uri))
130 };
131
132 // Add a timeout for curl to abort when the download speed keeps low
133 // (1 byte per second by default) for the specified duration. See:
134 // https://curl.haxx.se/docs/manpage.html#-y
135 if (flags.curl_stall_timeout.isSome()) {
136 argv.push_back("-y");
137 argv.push_back(
138 std::to_string(static_cast<long>(flags.curl_stall_timeout->secs())));
139 }
140
141 Try<Subprocess> s = subprocess(
142 curl,
143 argv,
144 Subprocess::PATH(os::DEV_NULL),
145 Subprocess::PIPE(),
146 Subprocess::PIPE());
147

Callers

nothing calls this directly

Calls 15

FailureClass · 0.85
PathClass · 0.85
from_uriFunction · 0.85
trimFunction · 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

Tested by

no test coverage detected