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);
alt_req->url);
active_requests++;
slot->in_use = 1;
- if (start_active_slot(slot)) {
- return;
- } else {
+ if (!start_active_slot(slot)) {
got_alternates = -1;
slot->in_use = 0;
- return;
}
+ return;
}
} else if (slot->curl_result != CURLE_OK) {
if (slot->http_code != 404 &&
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);
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;
}
} else if (memcmp(obj_req->sha1, obj_req->real_sha1, 20)) {
ret = error("File %s has bad hash\n", 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);