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;
}
free(obj_req->url);
return;
}
-
}
static void finish_object_request(struct object_request *obj_req)
obj_req->state = COMPLETE;
/* Use alternates if necessary */
- if (obj_req->http_code == 404) {
+ if (obj_req->http_code == 404 ||
+ obj_req->curl_result == CURLE_FILE_COULDNT_READ_FILE) {
fetch_alternates(alt->base);
if (obj_req->repo->next != NULL) {
obj_req->repo =
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);
slot->curl = NULL;
}
slot = slot->next;
- }
+ }
}
#endif
FILE *indexfile;
struct active_request_slot *slot;
+ 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");
filename);
slot = get_active_slot();
+ slot->results = &results;
curl_easy_setopt(slot->curl, CURLOPT_FILE, indexfile);
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
if (start_active_slot(slot)) {
run_active_slot(slot);
- if (slot->curl_result != CURLE_OK) {
+ if (results.curl_result != CURLE_OK) {
fclose(indexfile);
return error("Unable to get pack index %s\n%s", url,
curl_errorstr);
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) {
+ if (slot->http_code != 404 &&
+ slot->curl_result != CURLE_FILE_COULDNT_READ_FILE) {
got_alternates = -1;
return;
}
} 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--;
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, ':');
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;
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
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);
int i = 0;
struct active_request_slot *slot;
+ struct slot_results results;
if (repo->got_indices)
return 0;
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);
slot = get_active_slot();
+ slot->results = &results;
curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL);
if (start_active_slot(slot)) {
run_active_slot(slot);
- if (slot->curl_result != CURLE_OK) {
- if (slot->http_code == 404) {
+ if (results.curl_result != CURLE_OK) {
+ if (results.http_code == 404 ||
+ results.curl_result == CURLE_FILE_COULDNT_READ_FILE) {
repo->got_indices = 1;
free(buffer.buffer);
return 0;
struct curl_slist *range_header = NULL;
struct active_request_slot *slot;
+ struct slot_results results;
if (fetch_indices(repo))
return -1;
filename);
slot = get_active_slot();
+ slot->results = &results;
curl_easy_setopt(slot->curl, CURLOPT_FILE, packfile);
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
if (start_active_slot(slot)) {
run_active_slot(slot);
- if (slot->curl_result != CURLE_OK) {
+ if (results.curl_result != CURLE_OK) {
fclose(packfile);
return error("Unable to get pack file %s\n%s", url,
curl_errorstr);
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;
}
ret = error("Request for %s aborted", hex);
} else if (obj_req->curl_result != CURLE_OK &&
obj_req->http_code != 416) {
- if (obj_req->http_code == 404)
+ if (obj_req->http_code == 404 ||
+ obj_req->curl_result == CURLE_FILE_COULDNT_READ_FILE)
ret = -1; /* Be silent, it is probably in a pack. */
else
ret = error("%s (curl_result = %d, http_code = %ld, sha1 = %s)",
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);
+ 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);
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);
}
struct buffer buffer;
char *base = alt->base;
struct active_request_slot *slot;
+ 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;
curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL);
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
if (start_active_slot(slot)) {
run_active_slot(slot);
- if (slot->curl_result != CURLE_OK)
+ if (results.curl_result != CURLE_OK)
return error("Couldn't get %s for %s\n%s",
url, ref, curl_errorstr);
} else {