[PATCH] Return CURL error message when object transfer fails
Return CURL error message when object transfer fails [jc: added similar curl_errorstr errors to places where we use curl_easy_perform() to run fetch that _must_ succeed.] Signed-off-by: Nick Hengeveld <nickh@reactrix.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Nick Hengeveld committed
Sep 26, 2005 at 10:52 UTC
1ddea77e449ef28d8a7c74521af21121ab01abc0
1 file changed
+16
-8
http-fetch.c
+16
-8
@@ -15,6 +15,7 @@
15
16
static CURL *curl;
17
static struct curl_slist *no_pragma_header;
18
+static char curl_errorstr[CURL_ERROR_SIZE];
19
20
static char *initial_base;
21
@@ -112,10 +113,12 @@ static int fetch_index(struct alt_base *repo, unsigned char *sha1)
113
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
114
curl_easy_setopt(curl, CURLOPT_URL, url);
115
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, no_pragma_header);
116
+ curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorstr);
117
118
if (curl_easy_perform(curl)) {
119
fclose(indexfile);
118
- return error("Unable to get pack index %s", url);
120
+ return error("Unable to get pack index %s\n%s", url,
121
+ curl_errorstr);
122
}
123
124
fclose(indexfile);
@@ -264,10 +267,10 @@ static int fetch_indices(struct alt_base *repo)
267
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
268
curl_easy_setopt(curl, CURLOPT_URL, url);
269
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, NULL);
270
+ curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorstr);
271
268
- if (curl_easy_perform(curl)) {
269
- return -1;
270
- }
272
+ if (curl_easy_perform(curl))
273
+ return error("%s", curl_errorstr);
274
275
while (i < buffer.posn) {
276
switch (data[i]) {
@@ -327,10 +330,12 @@ static int fetch_pack(struct alt_base *repo, unsigned char *sha1)
330
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
331
curl_easy_setopt(curl, CURLOPT_URL, url);
332
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, no_pragma_header);
330
-
333
+ curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorstr);
334
+
335
if (curl_easy_perform(curl)) {
336
fclose(packfile);
333
- return error("Unable to get pack file %s", url);
337
+ return error("Unable to get pack file %s\n%s", url,
338
+ curl_errorstr);
339
}
340
341
fclose(packfile);
@@ -373,6 +378,7 @@ int fetch_object(struct alt_base *repo, unsigned char *sha1)
378
curl_easy_setopt(curl, CURLOPT_FILE, NULL);
379
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file);
380
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, no_pragma_header);
381
+ curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorstr);
382
383
url = xmalloc(strlen(repo->base) + 50);
384
strcpy(url, repo->base);
@@ -388,7 +394,7 @@ int fetch_object(struct alt_base *repo, unsigned char *sha1)
394
395
if (curl_easy_perform(curl)) {
396
unlink(filename);
391
- return -1;
397
+ return error("%s", curl_errorstr);
398
}
399
400
fchmod(local, 0444);
@@ -453,6 +459,7 @@ int fetch_ref(char *ref, unsigned char *sha1)
459
curl_easy_setopt(curl, CURLOPT_FILE, &buffer);
460
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
461
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, NULL);
462
+ curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorstr);
463
464
url = xmalloc(strlen(base) + 6 + strlen(ref));
465
strcpy(url, base);
@@ -464,7 +471,8 @@ int fetch_ref(char *ref, unsigned char *sha1)
471
curl_easy_setopt(curl, CURLOPT_URL, url);
472
473
if (curl_easy_perform(curl))
467
- return error("Couldn't get %s for %s\n", url, ref);
474
+ return error("Couldn't get %s for %s\n%s",
475
+ url, ref, curl_errorstr);
476
477
hex[40] = '\0';
478
get_sha1_hex(hex, sha1);