{"thread":{"id":"19580","subject":"[PATCH 02/17] http-walker: verify remote packs","startedAt":"2009-05-29T17:58:42Z","lastAt":"2009-05-29T17:58:42Z","messageCount":1,"participants":["Tay Ray Chuan"],"isPatch":true,"patchVersion":1,"patchTotal":17},"messages":[{"id":"115022","messageId":"20090530015842.0cff57d1.rctay89@gmail.com","threadId":"19580","inReplyTo":null,"subject":"[PATCH 02/17] http-walker: verify remote packs","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-05-29T17:58:42Z","receivedAt":"2009-05-29T17:58:42Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"In c17fb6e (\"Verify remote packs, speed up pending request queue\"),\nchanges were made to index fetching in http-push.c, particularly the\nmethods fetch_index and setup_index. Since http-walker.c has similar\ncode for index fetching, these improvements should apply to\nhttp-walker.c's fetch_index and setup_index.\n\nInvocations of free() of string memory are reproduced as well.\n\nSigned-off-by: Tay Ray Chuan <rctay89@gmail.com>\n---\n http-walker.c |   33 ++++++++++++++++++++++++++++++---\n 1 files changed, 30 insertions(+), 3 deletions(-)\n\ndiff --git a/http-walker.c b/http-walker.c\nindex dffb844..13ca934 100644\n--- a/http-walker.c\n+++ b/http-walker.c\n@@ -384,24 +384,48 @@ static int fetch_index(struct walker *walker, struct alt_base *repo, unsigned ch\n \tstruct active_request_slot *slot;\n \tstruct slot_results results;\n\n-\tif (has_pack_index(sha1))\n+\t/* Don't use the index if the pack isn't there */\n+\turl = xmalloc(strlen(repo->base) + 64);\n+\tsprintf(url, \"%s/objects/pack/pack-%s.pack\", repo->base, hex);\n+\tslot = get_active_slot();\n+\tslot->results = &results;\n+\tcurl_easy_setopt(slot->curl, CURLOPT_URL, url);\n+\tcurl_easy_setopt(slot->curl, CURLOPT_NOBODY, 1);\n+\tif (start_active_slot(slot)) {\n+\t\trun_active_slot(slot);\n+\t\tif (results.curl_result != CURLE_OK) {\n+\t\t\tfree(url);\n+\t\t\treturn error(\"Unable to verify pack %s is available\",\n+\t\t\t\t     hex);\n+\t\t}\n+\t} else {\n+\t\tfree(url);\n+\t\treturn error(\"Unable to start request\");\n+\t}\n+\n+\tif (has_pack_index(sha1)) {\n+\t\tfree(url);\n \t\treturn 0;\n+\t}\n\n \tif (walker->get_verbosely)\n \t\tfprintf(stderr, \"Getting index for pack %s\\n\", hex);\n\n-\turl = xmalloc(strlen(repo->base) + 64);\n \tsprintf(url, \"%s/objects/pack/pack-%s.idx\", repo->base, hex);\n\n \tfilename = sha1_pack_index_name(sha1);\n \tsnprintf(tmpfile, sizeof(tmpfile), \"%s.temp\", filename);\n \tindexfile = fopen(tmpfile, \"a\");\n-\tif (!indexfile)\n+\tif (!indexfile) {\n+\t\tfree(url);\n \t\treturn error(\"Unable to open local file %s for pack index\",\n \t\t\t     tmpfile);\n+\t}\n\n \tslot = get_active_slot();\n \tslot->results = &results;\n+\tcurl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);\n+\tcurl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);\n \tcurl_easy_setopt(slot->curl, CURLOPT_FILE, indexfile);\n \tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);\n \tcurl_easy_setopt(slot->curl, CURLOPT_URL, url);\n@@ -426,15 +450,18 @@ static int fetch_index(struct walker *walker, struct alt_base *repo, unsigned ch\n \tif (start_active_slot(slot)) {\n \t\trun_active_slot(slot);\n \t\tif (results.curl_result != CURLE_OK) {\n+\t\t\tfree(url);\n \t\t\tfclose(indexfile);\n \t\t\treturn error(\"Unable to get pack index %s\\n%s\", url,\n \t\t\t\t     curl_errorstr);\n \t\t}\n \t} else {\n+\t\tfree(url);\n \t\tfclose(indexfile);\n \t\treturn error(\"Unable to start request\");\n \t}\n\n+\tfree(url);\n \tfclose(indexfile);\n\n \treturn move_temp_to_file(tmpfile, filename);\n--\n1.6.3.1\n"}]}