http-walker: verify remote packs
In c17fb6e ("Verify remote packs, speed up pending request queue"), changes were made to index fetching in http-push.c, particularly the methods fetch_index and setup_index. Since http-walker.c has similar code for index fetching, these improvements should apply to http-walker.c's fetch_index and setup_index. Invocations of free() of string memory are reproduced as well. Signed-off-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Tay Ray Chuan committed
Jun 6, 2009 at 16:43 UTC
48188c259a7e6c87c20121933287b8c8ca721e3a
1 file changed
+30
-3
http-walker.c
+30
-3
@@ -384,24 +384,48 @@ static int fetch_index(struct walker *walker, struct alt_base *repo, unsigned ch
384
struct active_request_slot *slot;
385
struct slot_results results;
386
387
- if (has_pack_index(sha1))
387
+ /* Don't use the index if the pack isn't there */
388
+ url = xmalloc(strlen(repo->base) + 64);
389
+ sprintf(url, "%s/objects/pack/pack-%s.pack", repo->base, hex);
390
+ slot = get_active_slot();
391
+ slot->results = &results;
392
+ curl_easy_setopt(slot->curl, CURLOPT_URL, url);
393
+ curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 1);
394
+ if (start_active_slot(slot)) {
395
+ run_active_slot(slot);
396
+ if (results.curl_result != CURLE_OK) {
397
+ free(url);
398
+ return error("Unable to verify pack %s is available",
399
+ hex);
400
+ }
401
+ } else {
402
+ free(url);
403
+ return error("Unable to start request");
404
+ }
405
+
406
+ if (has_pack_index(sha1)) {
407
+ free(url);
408
return 0;
409
+ }
410
411
if (walker->get_verbosely)
412
fprintf(stderr, "Getting index for pack %s\n", hex);
413
393
- url = xmalloc(strlen(repo->base) + 64);
414
sprintf(url, "%s/objects/pack/pack-%s.idx", repo->base, hex);
415
416
filename = sha1_pack_index_name(sha1);
417
snprintf(tmpfile, sizeof(tmpfile), "%s.temp", filename);
418
indexfile = fopen(tmpfile, "a");
399
- if (!indexfile)
419
+ if (!indexfile) {
420
+ free(url);
421
return error("Unable to open local file %s for pack index",
422
tmpfile);
423
+ }
424
425
slot = get_active_slot();
426
slot->results = &results;
427
+ curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
428
+ curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
429
curl_easy_setopt(slot->curl, CURLOPT_FILE, indexfile);
430
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);
431
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
@@ -426,17 +450,20 @@ static int fetch_index(struct walker *walker, struct alt_base *repo, unsigned ch
450
if (start_active_slot(slot)) {
451
run_active_slot(slot);
452
if (results.curl_result != CURLE_OK) {
453
+ free(url);
454
fclose(indexfile);
455
slot->local = NULL;
456
return error("Unable to get pack index %s\n%s", url,
457
curl_errorstr);
458
}
459
} else {
460
+ free(url);
461
fclose(indexfile);
462
slot->local = NULL;
463
return error("Unable to start request");
464
}
465
466
+ free(url);
467
fclose(indexfile);
468
slot->local = NULL;
469