From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS2116 193.90.0.0/16 X-Spam-Status: No, score=-0.2 required=3.0 tests=AWL,BAYES_00, RCVD_IN_MSPIKE_BL,RCVD_IN_MSPIKE_ZBI,RCVD_IN_XBL,RDNS_NONE,SPF_FAIL, SPF_HELO_FAIL,URIBL_RED shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from 80x24.org (unknown [193.90.12.89]) by dcvr.yhbt.net (Postfix) with ESMTP id 7A5072018F for ; Sun, 10 Jul 2016 11:46:32 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH 2/4] http: avoid disconnecting on 404s for loose objects Date: Sun, 10 Jul 2016 11:46:25 +0000 Message-Id: <20160710114627.21504-2-e@80x24.org> In-Reply-To: <20160710114627.21504-1-e@80x24.org> References: <20160710114627.21504-1-e@80x24.org> List-Id: Signed-off-by: Eric Wong --- http-walker.c | 9 +++++++++ http.c | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/http-walker.c b/http-walker.c index 9f28523..48f2df4 100644 --- a/http-walker.c +++ b/http-walker.c @@ -488,6 +488,15 @@ static int fetch_object(struct walker *walker, unsigned char *sha1) req->localfile = -1; } + /* + * we turned off CURLOPT_FAILONERROR to avoid losing a + * persistent connection and got CURLE_OK. + */ + if (req->http_code == 404 && req->curl_result == CURLE_OK && + (starts_with(req->url, "http://") || + starts_with(req->url, "https://"))) + req->curl_result = CURLE_HTTP_RETURNED_ERROR; + if (obj_req->state == ABORTED) { ret = error("Request for %s aborted", hex); } else if (req->curl_result != CURLE_OK && diff --git a/http.c b/http.c index d8b2bec..afb25e1 100644 --- a/http.c +++ b/http.c @@ -1975,8 +1975,20 @@ static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb, unsigned char expn[4096]; size_t size = eltsize * nmemb; int posn = 0; - struct http_object_request *freq = - (struct http_object_request *)data; + struct http_object_request *freq = data; + struct active_request_slot *slot = freq->slot; + CURL *curl = slot->curl; + + if (curl) { + CURLcode c = curl_easy_getinfo(curl, CURLINFO_HTTP_CODE, + &slot->http_code); + if (c != CURLE_OK) + die("BUG: curl_easy_getinfo for HTTP code failed: %s", + curl_easy_strerror(c)); + if (slot->http_code >= 400) + return size; + } + do { ssize_t retval = xwrite(freq->localfile, (char *) ptr + posn, size - posn); @@ -2097,6 +2109,7 @@ struct http_object_request *new_http_object_request(const char *base_url, freq->slot = get_active_slot(); curl_easy_setopt(freq->slot->curl, CURLOPT_FILE, freq); + curl_easy_setopt(freq->slot->curl, CURLOPT_FAILONERROR, 0); curl_easy_setopt(freq->slot->curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file); curl_easy_setopt(freq->slot->curl, CURLOPT_ERRORBUFFER, freq->errorstr); curl_easy_setopt(freq->slot->curl, CURLOPT_URL, freq->url); -- EW