| 479 | } |
| 480 | |
| 481 | static int fetch_object(struct walker *walker, const struct object_id *oid) |
| 482 | { |
| 483 | char *hex = oid_to_hex(oid); |
| 484 | int ret = 0; |
| 485 | struct object_request *obj_req = NULL; |
| 486 | struct http_object_request *req; |
| 487 | struct list_head *pos, *head = &object_queue_head; |
| 488 | |
| 489 | list_for_each(pos, head) { |
| 490 | obj_req = list_entry(pos, struct object_request, node); |
| 491 | if (oideq(&obj_req->oid, oid)) |
| 492 | break; |
| 493 | } |
| 494 | if (!obj_req) |
| 495 | return error("Couldn't find request for %s in the queue", hex); |
| 496 | |
| 497 | if (odb_has_object(the_repository->objects, &obj_req->oid, |
| 498 | ODB_HAS_OBJECT_RECHECK_PACKED | ODB_HAS_OBJECT_FETCH_PROMISOR)) { |
| 499 | if (obj_req->req) |
| 500 | abort_http_object_request(&obj_req->req); |
| 501 | abort_object_request(obj_req); |
| 502 | return 0; |
| 503 | } |
| 504 | |
| 505 | while (obj_req->state == WAITING) |
| 506 | step_active_slots(); |
| 507 | |
| 508 | /* |
| 509 | * obj_req->req might change when fetching alternates in the callback |
| 510 | * process_object_response; therefore, the "shortcut" variable, req, |
| 511 | * is used only after we're done with slots. |
| 512 | */ |
| 513 | while (obj_req->state == ACTIVE) |
| 514 | run_active_slot(obj_req->req->slot); |
| 515 | |
| 516 | req = obj_req->req; |
| 517 | |
| 518 | if (req->localfile != -1) { |
| 519 | close(req->localfile); |
| 520 | req->localfile = -1; |
| 521 | } |
| 522 | |
| 523 | normalize_curl_result(&req->curl_result, req->http_code, |
| 524 | req->errorstr, sizeof(req->errorstr)); |
| 525 | |
| 526 | if (obj_req->state == ABORTED) { |
| 527 | ret = error("Request for %s aborted", hex); |
| 528 | } else if (req->curl_result != CURLE_OK && |
| 529 | req->http_code != 416) { |
| 530 | if (missing_target(req)) |
| 531 | ret = -1; /* Be silent, it is probably in a pack. */ |
| 532 | else |
| 533 | ret = error("%s (curl_result = %d, http_code = %ld, sha1 = %s)", |
| 534 | req->errorstr, req->curl_result, |
| 535 | req->http_code, hex); |
| 536 | } else if (req->zret != Z_STREAM_END) { |
| 537 | walker->corrupt_object_found++; |
| 538 | ret = error("File %s (%s) corrupt", hex, req->url); |
no test coverage detected