| 2736 | } |
| 2737 | |
| 2738 | struct http_pack_request *new_direct_http_pack_request( |
| 2739 | const unsigned char *packed_git_hash, char *url) |
| 2740 | { |
| 2741 | off_t prev_posn = 0; |
| 2742 | struct http_pack_request *preq; |
| 2743 | |
| 2744 | CALLOC_ARRAY(preq, 1); |
| 2745 | strbuf_init(&preq->tmpfile, 0); |
| 2746 | |
| 2747 | preq->url = url; |
| 2748 | |
| 2749 | odb_pack_name(the_repository, &preq->tmpfile, packed_git_hash, "pack"); |
| 2750 | strbuf_addstr(&preq->tmpfile, ".temp"); |
| 2751 | preq->packfile = fopen(preq->tmpfile.buf, "a"); |
| 2752 | if (!preq->packfile) { |
| 2753 | error("Unable to open local file %s for pack", |
| 2754 | preq->tmpfile.buf); |
| 2755 | goto abort; |
| 2756 | } |
| 2757 | |
| 2758 | preq->slot = get_active_slot(); |
| 2759 | preq->headers = object_request_headers(); |
| 2760 | curl_easy_setopt(preq->slot->curl, CURLOPT_WRITEDATA, preq->packfile); |
| 2761 | curl_easy_setopt(preq->slot->curl, CURLOPT_WRITEFUNCTION, fwrite); |
| 2762 | curl_easy_setopt(preq->slot->curl, CURLOPT_URL, preq->url); |
| 2763 | curl_easy_setopt(preq->slot->curl, CURLOPT_HTTPHEADER, preq->headers); |
| 2764 | |
| 2765 | /* |
| 2766 | * If there is data present from a previous transfer attempt, |
| 2767 | * resume where it left off |
| 2768 | */ |
| 2769 | prev_posn = ftello(preq->packfile); |
| 2770 | if (prev_posn>0) { |
| 2771 | if (http_is_verbose) |
| 2772 | fprintf(stderr, |
| 2773 | "Resuming fetch of pack %s at byte %"PRIuMAX"\n", |
| 2774 | hash_to_hex(packed_git_hash), |
| 2775 | (uintmax_t)prev_posn); |
| 2776 | http_opt_request_remainder(preq->slot->curl, prev_posn); |
| 2777 | } |
| 2778 | |
| 2779 | return preq; |
| 2780 | |
| 2781 | abort: |
| 2782 | strbuf_release(&preq->tmpfile); |
| 2783 | free(preq->url); |
| 2784 | free(preq); |
| 2785 | return NULL; |
| 2786 | } |
| 2787 | |
| 2788 | /* Helpers for fetching objects (loose) */ |
| 2789 | static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb, |
no test coverage detected