* Downloads a URL and stores the result in the given file. * * If a previous interrupted download is detected (i.e. a previous temporary * file is still around) the download is resumed. */
| 2498 | * file is still around) the download is resumed. |
| 2499 | */ |
| 2500 | int http_get_file(const char *url, const char *filename, |
| 2501 | struct http_get_options *options) |
| 2502 | { |
| 2503 | int ret; |
| 2504 | struct strbuf tmpfile = STRBUF_INIT; |
| 2505 | FILE *result; |
| 2506 | |
| 2507 | strbuf_addf(&tmpfile, "%s.temp", filename); |
| 2508 | result = fopen(tmpfile.buf, "a"); |
| 2509 | if (!result) { |
| 2510 | error("Unable to open local file %s", tmpfile.buf); |
| 2511 | ret = HTTP_ERROR; |
| 2512 | goto cleanup; |
| 2513 | } |
| 2514 | |
| 2515 | ret = http_request_recoverable(url, result, HTTP_REQUEST_FILE, options); |
| 2516 | fclose(result); |
| 2517 | |
| 2518 | if (ret == HTTP_OK && finalize_object_file(the_repository, tmpfile.buf, filename)) |
| 2519 | ret = HTTP_ERROR; |
| 2520 | cleanup: |
| 2521 | strbuf_release(&tmpfile); |
| 2522 | return ret; |
| 2523 | } |
| 2524 | |
| 2525 | int http_fetch_ref(const char *base, struct ref *ref) |
| 2526 | { |
no test coverage detected