static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
void *data)
static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
void *data)
- request->stream.next_out = expn;
- request->stream.avail_out = sizeof(expn);
- request->zret = inflate(&request->stream, Z_SYNC_FLUSH);
- SHA1_Update(&request->c, expn,
- sizeof(expn) - request->stream.avail_out);
- } while (request->stream.avail_in && request->zret == Z_OK);
+ obj_req->stream.next_out = expn;
+ obj_req->stream.avail_out = sizeof(expn);
+ obj_req->zret = inflate(&obj_req->stream, Z_SYNC_FLUSH);
+ SHA1_Update(&obj_req->c, expn,
+ sizeof(expn) - obj_req->stream.avail_out);
+ } while (obj_req->stream.avail_in && obj_req->zret == Z_OK);
- snprintf(prevfile, sizeof(prevfile), "%s.prev", request->filename);
+ snprintf(prevfile, sizeof(prevfile), "%s.prev", obj_req->filename);
- rename(request->tmpfile, prevfile);
- unlink(request->tmpfile);
+ rename(obj_req->tmpfile, prevfile);
+ unlink(obj_req->tmpfile);
- if (request->local != -1)
- error("fd leakage in start: %d", request->local);
- request->local = open(request->tmpfile,
+ if (obj_req->local != -1)
+ error("fd leakage in start: %d", obj_req->local);
+ obj_req->local = open(obj_req->tmpfile,
O_WRONLY | O_CREAT | O_EXCL, 0666);
/* This could have failed due to the "lazy directory creation";
* try to mkdir the last path component.
*/
O_WRONLY | O_CREAT | O_EXCL, 0666);
/* This could have failed due to the "lazy directory creation";
* try to mkdir the last path component.
*/
- if (request->local < 0 && errno == ENOENT) {
- char *dir = strrchr(request->tmpfile, '/');
+ if (obj_req->local < 0 && errno == ENOENT) {
+ char *dir = strrchr(obj_req->tmpfile, '/');
- url = xmalloc(strlen(request->repo->base) + 50);
- request->url = xmalloc(strlen(request->repo->base) + 50);
- strcpy(url, request->repo->base);
- posn = url + strlen(request->repo->base);
+ url = xmalloc(strlen(obj_req->repo->base) + 50);
+ obj_req->url = xmalloc(strlen(obj_req->repo->base) + 50);
+ strcpy(url, obj_req->repo->base);
+ posn = url + strlen(obj_req->repo->base);
/* Reset inflate/SHA1 if there was an error reading the previous temp
file; also rewind to the beginning of the local file. */
if (prev_read == -1) {
/* Reset inflate/SHA1 if there was an error reading the previous temp
file; also rewind to the beginning of the local file. */
if (prev_read == -1) {
- memset(&request->stream, 0, sizeof(request->stream));
- inflateInit(&request->stream);
- SHA1_Init(&request->c);
+ memset(&obj_req->stream, 0, sizeof(obj_req->stream));
+ inflateInit(&obj_req->stream);
+ SHA1_Init(&obj_req->c);
- lseek(request->local, SEEK_SET, 0);
- ftruncate(request->local, 0);
+ lseek(obj_req->local, SEEK_SET, 0);
+ ftruncate(obj_req->local, 0);
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
- fchmod(request->local, 0444);
- close(request->local); request->local = -1;
+ fchmod(obj_req->local, 0444);
+ close(obj_req->local); obj_req->local = -1;
- } else if (request->curl_result != CURLE_OK) {
- if (stat(request->tmpfile, &st) == 0)
+ } else if (obj_req->curl_result != CURLE_OK) {
+ if (stat(obj_req->tmpfile, &st) == 0)
- inflateEnd(&request->stream);
- SHA1_Final(request->real_sha1, &request->c);
- if (request->zret != Z_STREAM_END) {
- unlink(request->tmpfile);
+ inflateEnd(&obj_req->stream);
+ SHA1_Final(obj_req->real_sha1, &obj_req->c);
+ if (obj_req->zret != Z_STREAM_END) {
+ unlink(obj_req->tmpfile);
- if (memcmp(request->sha1, request->real_sha1, 20)) {
- unlink(request->tmpfile);
+ if (memcmp(obj_req->sha1, obj_req->real_sha1, 20)) {
+ unlink(obj_req->tmpfile);
- if (request->rename == 0)
- pull_say("got %s\n", sha1_to_hex(request->sha1));
+ if (obj_req->rename == 0)
+ pull_say("got %s\n", sha1_to_hex(obj_req->sha1));
- request->curl_result = request->slot->curl_result;
- request->http_code = request->slot->http_code;
- request->slot = NULL;
- request->state = COMPLETE;
+ obj_req->curl_result = obj_req->slot->curl_result;
+ obj_req->http_code = obj_req->slot->http_code;
+ obj_req->slot = NULL;
+ obj_req->state = COMPLETE;
- if (request->local != -1)
- error("fd leakage in release: %d", request->local);
- if (request == request_queue_head) {
- request_queue_head = request->next;
+ if (obj_req->local != -1)
+ error("fd leakage in release: %d", obj_req->local);
+ if (obj_req == object_queue_head) {
+ object_queue_head = obj_req->next;
- while (active_requests < max_requests && request != NULL) {
- if (request->state == WAITING) {
- if (has_sha1_file(request->sha1))
- release_request(request);
+ 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);
struct active_request_slot *slot = alt_req->slot;
struct alt_base *tail = alt;
char *base = alt_req->base;
struct active_request_slot *slot = alt_req->slot;
struct alt_base *tail = alt;
char *base = alt_req->base;
/* If another request has already started fetching alternates,
wait for them to arrive and return to processing this request's
/* If another request has already started fetching alternates,
wait for them to arrive and return to processing this request's
/* Use a callback to process the result, since another request
may fail and need to have alternates loaded before continuing */
slot = get_active_slot();
/* Use a callback to process the result, since another request
may fail and need to have alternates loaded before continuing */
slot = get_active_slot();
slot->callback_data = &alt_req;
curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
slot->callback_data = &alt_req;
curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
- while (request != NULL && memcmp(request->sha1, sha1, 20))
- request = request->next;
- if (request == NULL)
+ while (obj_req != NULL && memcmp(obj_req->sha1, sha1, 20))
+ obj_req = obj_req->next;
+ if (obj_req == NULL)
- } else if (request->curl_result != CURLE_OK &&
- request->http_code != 416) {
- if (request->http_code == 404)
+ } else if (obj_req->curl_result != CURLE_OK &&
+ obj_req->http_code != 416) {
+ if (obj_req->http_code == 404)
ret = -1; /* Be silent, it is probably in a pack. */
else
ret = error("%s (curl_result = %d, http_code = %ld, sha1 = %s)",
ret = -1; /* Be silent, it is probably in a pack. */
else
ret = error("%s (curl_result = %d, http_code = %ld, sha1 = %s)",
- request->errorstr, request->curl_result,
- request->http_code, hex);
- } else if (request->zret != Z_STREAM_END) {
- ret = error("File %s (%s) corrupt\n", hex, request->url);
- } else if (memcmp(request->sha1, request->real_sha1, 20)) {
+ 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);
+ } else if (memcmp(obj_req->sha1, obj_req->real_sha1, 20)) {