@@ -798,40 +798,22 @@ static int fetch_pack_index(unsigned char *sha1, const char *base_url)
798798 char * hex = xstrdup (sha1_to_hex (sha1 ));
799799 char * filename ;
800800 char * url ;
801- char tmpfile [PATH_MAX ];
802- long prev_posn = 0 ;
803- char range [RANGE_HEADER_SIZE ];
804801 struct strbuf buf = STRBUF_INIT ;
805- struct curl_slist * range_header = NULL ;
806-
807- FILE * indexfile ;
808- struct active_request_slot * slot ;
809- struct slot_results results ;
810802
811803 /* Don't use the index if the pack isn't there */
812804 end_url_with_slash (& buf , base_url );
813805 strbuf_addf (& buf , "objects/pack/pack-%s.pack" , hex );
814806 url = strbuf_detach (& buf , 0 );
815807
816- slot = get_active_slot ();
817- slot -> results = & results ;
818- curl_easy_setopt (slot -> curl , CURLOPT_URL , url );
819- curl_easy_setopt (slot -> curl , CURLOPT_NOBODY , 1 );
820- if (start_active_slot (slot )) {
821- run_active_slot (slot );
822- if (results .curl_result != CURLE_OK ) {
823- ret = error ("Unable to verify pack %s is available" ,
824- hex );
825- goto cleanup_pack ;
826- }
827- } else {
828- ret = error ("Unable to start request" );
829- goto cleanup_pack ;
808+ if (http_get_strbuf (url , NULL , 0 )) {
809+ ret = error ("Unable to verify pack %s is available" ,
810+ hex );
811+ goto cleanup ;
830812 }
831813
832814 if (has_pack_index (sha1 )) {
833815 ret = 0 ;
834- goto cleanup_pack ;
816+ goto cleanup ;
835817 }
836818
837819 if (http_is_verbose )
@@ -842,57 +824,10 @@ static int fetch_pack_index(unsigned char *sha1, const char *base_url)
842824 url = strbuf_detach (& buf , NULL );
843825
844826 filename = sha1_pack_index_name (sha1 );
845- snprintf (tmpfile , sizeof (tmpfile ), "%s.temp" , filename );
846- indexfile = fopen (tmpfile , "a" );
847- if (!indexfile ) {
848- ret = error ("Unable to open local file %s for pack index" ,
849- tmpfile );
850- goto cleanup_pack ;
851- }
827+ if (http_get_file (url , filename , 0 ) != HTTP_OK )
828+ ret = error ("Unable to get pack index %s\n" , url );
852829
853- slot = get_active_slot ();
854- slot -> results = & results ;
855- curl_easy_setopt (slot -> curl , CURLOPT_NOBODY , 0 );
856- curl_easy_setopt (slot -> curl , CURLOPT_HTTPGET , 1 );
857- curl_easy_setopt (slot -> curl , CURLOPT_FILE , indexfile );
858- curl_easy_setopt (slot -> curl , CURLOPT_WRITEFUNCTION , fwrite );
859- curl_easy_setopt (slot -> curl , CURLOPT_URL , url );
860- curl_easy_setopt (slot -> curl , CURLOPT_HTTPHEADER , no_pragma_header );
861- slot -> local = indexfile ;
862-
863- /*
864- * If there is data present from a previous transfer attempt,
865- * resume where it left off
866- */
867- prev_posn = ftell (indexfile );
868- if (prev_posn > 0 ) {
869- if (http_is_verbose )
870- fprintf (stderr ,
871- "Resuming fetch of index for pack %s at byte %ld\n" ,
872- hex , prev_posn );
873- sprintf (range , "Range: bytes=%ld-" , prev_posn );
874- range_header = curl_slist_append (range_header , range );
875- curl_easy_setopt (slot -> curl , CURLOPT_HTTPHEADER , range_header );
876- }
877-
878- if (start_active_slot (slot )) {
879- run_active_slot (slot );
880- if (results .curl_result != CURLE_OK ) {
881- ret = error ("Unable to get pack index %s\n%s" ,
882- url , curl_errorstr );
883- goto cleanup_index ;
884- }
885- } else {
886- ret = error ("Unable to start request" );
887- goto cleanup_index ;
888- }
889-
890- ret = move_temp_to_file (tmpfile , filename );
891-
892- cleanup_index :
893- fclose (indexfile );
894- slot -> local = NULL ;
895- cleanup_pack :
830+ cleanup :
896831 free (hex );
897832 free (url );
898833 return ret ;
0 commit comments