aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2012-02-07 22:06:03 +0100
committerYang Tse <yangsita@gmail.com>2012-02-07 22:10:01 +0100
commit4405039fdcc60f6348c8d69159953f18a5c11fed (patch)
treea9389c3c46ed38cc40b983235227af0449d9a193
parent65103efe49a733ba0a4e50c8bd1e318ed31463f4 (diff)
curl tool: allow glob-loops to abort again upon critical errors
This prevents clobbering of non recoverable error return codes while retaining intended functionality of commit 65103efe
-rw-r--r--src/tool_operate.c48
1 files changed, 37 insertions, 11 deletions
diff --git a/src/tool_operate.c b/src/tool_operate.c
index d086ac50a..e113ecdfc 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -102,6 +102,24 @@
"If you'd like to turn off curl's verification of the certificate, use\n" \
" the -k (or --insecure) option.\n"
+static int is_fatal_error(int code)
+{
+ switch(code) {
+ /* TODO: Should CURLE_SSL_CACERT be included as critical error ? */
+ case CURLE_FAILED_INIT:
+ case CURLE_OUT_OF_MEMORY:
+ case CURLE_UNKNOWN_OPTION:
+ case CURLE_FUNCTION_NOT_FOUND:
+ case CURLE_BAD_FUNCTION_ARGUMENT:
+ /* critical error */
+ return 1;
+ default:
+ break;
+ }
+ /* no error or not critical */
+ return 0;
+}
+
int operate(struct Configurable *config, int argc, argv_item_t argv[])
{
char errorbuffer[CURL_ERROR_SIZE];
@@ -1463,6 +1481,15 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
infd = STDIN_FILENO;
}
+ if(urlnum > 1) {
+ /* when url globbing, exit loop upon critical error */
+ if(is_fatal_error(res))
+ break;
+ }
+ else if(res)
+ /* when not url globbing, exit loop upon any error */
+ break;
+
} /* loop to the next URL */
/* Free loop-local allocated memory */
@@ -1475,6 +1502,15 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
urls = NULL;
}
+ if(infilenum > 1) {
+ /* when file globbing, exit loop upon critical error */
+ if(is_fatal_error(res))
+ break;
+ }
+ else if(res)
+ /* when not file globbing, exit loop upon any error */
+ break;
+
} /* loop to the next globbed upload file */
/* Free loop-local allocated memory */
@@ -1494,21 +1530,11 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
Curl_safefree(urlnode->infile);
urlnode->flags = 0;
- /* TODO: Should CURLE_SSL_CACERT be included as critical error ? */
-
/*
** Bail out upon critical errors
*/
- switch(res) {
- case CURLE_FAILED_INIT:
- case CURLE_OUT_OF_MEMORY:
- case CURLE_FUNCTION_NOT_FOUND:
- case CURLE_BAD_FUNCTION_ARGUMENT:
+ if(is_fatal_error(res))
goto quit_curl;
- default:
- /* Merrily loop to next URL */
- break;
- }
} /* for-loop through all URLs */