]> granicus.if.org Git - curl/commitdiff
curl tool: allow glob-loops to abort again upon critical errors
authorYang Tse <yangsita@gmail.com>
Tue, 7 Feb 2012 21:06:03 +0000 (22:06 +0100)
committerYang Tse <yangsita@gmail.com>
Tue, 7 Feb 2012 21:10:01 +0000 (22:10 +0100)
This prevents clobbering of non recoverable error return codes while
retaining intended functionality of commit 65103efe

src/tool_operate.c

index d086ac50abf6e13411a082f488f835423dc2c64a..e113ecdfc457efcb28df1eb15301f62d87690092 100644 (file)
   "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 */