Returns the resulting file or in case of extraction the destination directory (for logging).
| 282 | // Returns the resulting file or in case of extraction the destination |
| 283 | // directory (for logging). |
| 284 | static Try<string> fetchBypassingCache( |
| 285 | const CommandInfo::URI& uri, |
| 286 | const string& sandboxDirectory, |
| 287 | const Option<string>& frameworksHome, |
| 288 | const Option<Duration>& stallTimeout) |
| 289 | { |
| 290 | LOG(INFO) << "Fetching '" << uri.value() |
| 291 | << "' directly into the sandbox directory"; |
| 292 | |
| 293 | // TODO(mrbrowning): Factor out duplicated processing of "output_file" field |
| 294 | // here and in fetchFromCache into a separate helper function. |
| 295 | if (uri.has_output_file()) { |
| 296 | string dirname = Path(uri.output_file()).dirname(); |
| 297 | if (dirname != ".") { |
| 298 | Try<Nothing> result = |
| 299 | os::mkdir(path::join(sandboxDirectory, dirname), true); |
| 300 | |
| 301 | if (result.isError()) { |
| 302 | return Error( |
| 303 | "Unable to create subdirectory " + dirname + |
| 304 | " in sandbox: " + result.error()); |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | Try<string> outputFile = uri.has_output_file() |
| 310 | ? uri.output_file() |
| 311 | : Fetcher::basename(uri.value()); |
| 312 | |
| 313 | if (outputFile.isError()) { |
| 314 | return Error(outputFile.error()); |
| 315 | } |
| 316 | |
| 317 | string path = path::join(sandboxDirectory, outputFile.get()); |
| 318 | |
| 319 | Try<string> downloaded = |
| 320 | download(uri.value(), path, frameworksHome, stallTimeout); |
| 321 | if (downloaded.isError()) { |
| 322 | return Error(downloaded.error()); |
| 323 | } |
| 324 | |
| 325 | if (uri.executable()) { |
| 326 | return chmodExecutable(downloaded.get()); |
| 327 | } else if (uri.extract()) { |
| 328 | Try<bool> extracted = extract(path, sandboxDirectory); |
| 329 | if (extracted.isError()) { |
| 330 | return Error(extracted.error()); |
| 331 | } else if (!extracted.get()) { |
| 332 | LOG(WARNING) << "Copying instead of extracting resource from URI with " |
| 333 | << "'extract' flag, because it does not seem to be an " |
| 334 | << "archive: " << uri.value(); |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | return downloaded; |
| 339 | } |
| 340 | |
| 341 |
no test coverage detected