X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=http-fetch.c;h=dc67218ae7caba09add888bc0da165d6c0c10930;hb=5cdeae71ea7330c08cf96b581e2c7696949e3840;hp=92326f9ac50bfb0edecb762d81e26fa134bcf120;hpb=c8568e139ed2149fbfb7ef9a8d819d5b6b7c554f;p=git.git diff --git a/http-fetch.c b/http-fetch.c index 92326f9a..dc67218a 100644 --- a/http-fetch.c +++ b/http-fetch.c @@ -8,6 +8,7 @@ #define RANGE_HEADER_SIZE 30 static int got_alternates = -1; +static int corrupt_object_found = 0; static struct curl_slist *no_pragma_header; @@ -130,7 +131,7 @@ static void start_object_request(struct object_request *obj_req) if (obj_req->local < 0) { obj_req->state = ABORTED; - error("Couldn't create temporary file %s for %s: %s\n", + error("Couldn't create temporary file %s for %s: %s", obj_req->tmpfile, obj_req->filename, strerror(errno)); return; } @@ -220,7 +221,6 @@ static void start_object_request(struct object_request *obj_req) free(obj_req->url); return; } - } static void finish_object_request(struct object_request *obj_req) @@ -312,7 +312,7 @@ void fill_active_slots(void) while (active_requests < max_requests && obj_req != NULL) { if (obj_req->state == WAITING) { if (has_sha1_file(obj_req->sha1)) - release_object_request(obj_req); + obj_req->state = COMPLETE; else start_object_request(obj_req); curl_multi_perform(curlm, &num_transfers); @@ -326,7 +326,7 @@ void fill_active_slots(void) slot->curl = NULL; } slot = slot->next; - } + } } #endif @@ -375,17 +375,17 @@ static int fetch_index(struct alt_base *repo, unsigned char *sha1) FILE *indexfile; struct active_request_slot *slot; - static struct slot_results results; + struct slot_results results; if (has_pack_index(sha1)) return 0; if (get_verbosely) fprintf(stderr, "Getting index for pack %s\n", hex); - + url = xmalloc(strlen(repo->base) + 64); sprintf(url, "%s/objects/pack/pack-%s.idx", repo->base, hex); - + filename = sha1_pack_index_name(sha1); snprintf(tmpfile, sizeof(tmpfile), "%s.temp", filename); indexfile = fopen(tmpfile, "a"); @@ -469,13 +469,15 @@ static void process_alternates_response(void *callback_data) alt_req->url); active_requests++; slot->in_use = 1; - if (start_active_slot(slot)) { - return; - } else { + if (slot->finished != NULL) + (*slot->finished) = 0; + if (!start_active_slot(slot)) { got_alternates = -1; slot->in_use = 0; - return; + if (slot->finished != NULL) + (*slot->finished) = 1; } + return; } } else if (slot->curl_result != CURLE_OK) { if (slot->http_code != 404 && @@ -504,7 +506,7 @@ static void process_alternates_response(void *callback_data) } else if (!memcmp(data + i, "../", 3)) { i += 3; serverlen = strlen(base); - while (i + 2 < posn && + while (i + 2 < posn && !memcmp(data + i, "../", 3)) { do { serverlen--; @@ -513,7 +515,7 @@ static void process_alternates_response(void *callback_data) i += 3; } // If the server got removed, give up. - okay = strchr(base, ':') - base + 3 < + okay = strchr(base, ':') - base + 3 < serverlen; } else if (alt_req->http_specific) { char *colon = strchr(data + i, ':'); @@ -531,7 +533,7 @@ static void process_alternates_response(void *callback_data) posn - i - 7); target[serverlen + posn - i - 7] = '\0'; if (get_verbosely) - fprintf(stderr, + fprintf(stderr, "Also look at %s\n", target); newalt = xmalloc(sizeof(*newalt)); newalt->next = NULL; @@ -555,7 +557,7 @@ static void fetch_alternates(char *base) char *url; char *data; struct active_request_slot *slot; - static struct alternates_request alt_req; + struct alternates_request alt_req; /* If another request has already started fetching alternates, wait for them to arrive and return to processing this request's @@ -580,7 +582,7 @@ static void fetch_alternates(char *base) if (get_verbosely) fprintf(stderr, "Getting alternates list for %s\n", base); - + url = xmalloc(strlen(base) + 31); sprintf(url, "%s/objects/info/http-alternates", base); @@ -618,7 +620,7 @@ static int fetch_indices(struct alt_base *repo) int i = 0; struct active_request_slot *slot; - static struct slot_results results; + struct slot_results results; if (repo->got_indices) return 0; @@ -630,7 +632,7 @@ static int fetch_indices(struct alt_base *repo) if (get_verbosely) fprintf(stderr, "Getting pack list for %s\n", repo->base); - + url = xmalloc(strlen(repo->base) + 21); sprintf(url, "%s/objects/info/packs", repo->base); @@ -699,7 +701,7 @@ static int fetch_pack(struct alt_base *repo, unsigned char *sha1) struct curl_slist *range_header = NULL; struct active_request_slot *slot; - static struct slot_results results; + struct slot_results results; if (fetch_indices(repo)) return -1; @@ -776,6 +778,20 @@ static int fetch_pack(struct alt_base *repo, unsigned char *sha1) return 0; } +static void abort_object_request(struct object_request *obj_req) +{ + if (obj_req->local >= 0) { + close(obj_req->local); + obj_req->local = -1; + } + unlink(obj_req->tmpfile); + if (obj_req->slot) { + release_active_slot(obj_req->slot); + obj_req->slot = NULL; + } + release_object_request(obj_req); +} + static int fetch_object(struct alt_base *repo, unsigned char *sha1) { char *hex = sha1_to_hex(sha1); @@ -788,7 +804,7 @@ static int fetch_object(struct alt_base *repo, unsigned char *sha1) return error("Couldn't find request for %s in the queue", hex); if (has_sha1_file(obj_req->sha1)) { - release_object_request(obj_req); + abort_object_request(obj_req); return 0; } @@ -819,13 +835,13 @@ static int fetch_object(struct alt_base *repo, unsigned char *sha1) obj_req->errorstr, obj_req->curl_result, obj_req->http_code, hex); } else if (obj_req->zret != Z_STREAM_END) { - ret = error("File %s (%s) corrupt\n", hex, obj_req->url); + corrupt_object_found++; + ret = error("File %s (%s) corrupt", hex, obj_req->url); } else if (memcmp(obj_req->sha1, obj_req->real_sha1, 20)) { - ret = error("File %s has bad hash\n", hex); + ret = error("File %s has bad hash", hex); } else if (obj_req->rename < 0) { - ret = error("unable to write sha1 filename %s: %s", - obj_req->filename, - strerror(obj_req->rename)); + ret = error("unable to write sha1 filename %s", + obj_req->filename); } release_object_request(obj_req); @@ -844,7 +860,7 @@ int fetch(unsigned char *sha1) fetch_alternates(alt->base); altbase = altbase->next; } - return error("Unable to find %s under %s\n", sha1_to_hex(sha1), + return error("Unable to find %s under %s", sha1_to_hex(sha1), alt->base); } @@ -900,12 +916,12 @@ int fetch_ref(char *ref, unsigned char *sha1) struct buffer buffer; char *base = alt->base; struct active_request_slot *slot; - static struct slot_results results; + struct slot_results results; buffer.size = 41; buffer.posn = 0; buffer.buffer = hex; hex[41] = '\0'; - + url = quote_ref_url(base, ref); slot = get_active_slot(); slot->results = &results; @@ -979,5 +995,11 @@ int main(int argc, char **argv) http_cleanup(); + if (corrupt_object_found) { + fprintf(stderr, +"Some loose object were found to be corrupt, but they might be just\n" +"a false '404 Not Found' error message sent with incorrect HTTP\n" +"status code. Suggest running git fsck-objects.\n"); + } return rc; }