]> sjero.net Git - wget/commitdiff
[svn] Gracefully handle opt.downloaded overflowing.
authorhniksic <devnull@localhost>
Wed, 1 Nov 2000 23:17:31 +0000 (15:17 -0800)
committerhniksic <devnull@localhost>
Wed, 1 Nov 2000 23:17:31 +0000 (15:17 -0800)
Published in <sxsd7gfnv17.fsf@florida.arsdigita.de>.

src/ChangeLog
src/ftp.c
src/http.c
src/main.c
src/options.h
src/recur.c
src/retr.c
src/retr.h
src/wget.h

index d62a181fedae7ba0cefb38888de978be4f392d67..18f28cc4d2ecee3218c5d27d5af67a983e363df3 100644 (file)
@@ -1,3 +1,34 @@
+2000-11-01  Hrvoje Niksic  <hniksic@arsdigita.com>
+
+       * main.c (main): In case of opt.downloaded overflowing, print
+       <overflow> instead of a totally bogus random value.
+
+       * retr.c (retrieve_from_file): Ditto.
+
+       * recur.c (recursive_retrieve): Ditto.
+
+       * main.c (main): Ditto.
+
+       * http.c (http_loop): Ditto.
+
+       * ftp.c (ftp_loop_internal): Use downloaded_increase() instead of
+       `+=', and downloaded_exceeds_quota() instead of the simple-minded
+       check.
+       (ftp_retrieve_list): Ditto.
+       (ftp_retrieve_dirs): Ditto.
+       (ftp_retrieve_glob): Ditto.
+
+       * retr.c (downloaded_increase): New function.  Notice overflows of
+       opt.downloaded.
+       (downloaded_exceeds_quota): Make sure that opt.downloaded is not
+       used if it overflowed.
+
+       * options.h (struct options): New member downloaded_overflow.
+
+2000-11-01  Hrvoje Niksic  <hniksic@arsdigita.com>
+
+       * wget.h (enum): Remove extra space after last enumeration.
+
 2000-11-01  Hrvoje Niksic  <hniksic@arsdigita.com>
 
        * main.c (main): Use legible_very_long() for printing
index 7496a5aea914a418218a69f0d13031b28697c977..d2399311e6a56a2f0863b40668aa7b4109ad8bda 100644 (file)
--- a/src/ftp.c
+++ b/src/ftp.c
@@ -1006,7 +1006,7 @@ ftp_loop_internal (struct urlinfo *u, struct fileinfo *f, ccon *con)
            /* --dont-remove-listing was specified, so do count this towards the
               number of bytes and files downloaded. */
            {
-             opt.downloaded += len;
+             downloaded_increase (len);
              opt.numurls++;
            }
 
@@ -1021,7 +1021,7 @@ ftp_loop_internal (struct urlinfo *u, struct fileinfo *f, ccon *con)
             downloaded if they're going to be deleted.  People seeding proxies,
             for instance, may want to know how many bytes and files they've
             downloaded through it. */
-         opt.downloaded += len;
+         downloaded_increase (len);
          opt.numurls++;
 
          if (opt.delete_after)
@@ -1142,7 +1142,7 @@ ftp_retrieve_list (struct urlinfo *u, struct fileinfo *f, ccon *con)
 
   while (f)
     {
-      if (opt.quota && opt.downloaded > opt.quota)
+      if (downloaded_exceeds_quota ())
        {
          --depth;
          return QUOTEXC;
@@ -1308,7 +1308,7 @@ ftp_retrieve_dirs (struct urlinfo *u, struct fileinfo *f, ccon *con)
     {
       int len;
 
-      if (opt.quota && opt.downloaded > opt.quota)
+      if (downloaded_exceeds_quota ())
        break;
       if (f->type != FT_DIRECTORY)
        continue;
@@ -1429,7 +1429,7 @@ ftp_retrieve_glob (struct urlinfo *u, ccon *con, int action)
        }
     }
   freefileinfo (start);
-  if (opt.quota && opt.downloaded > opt.quota)
+  if (downloaded_exceeds_quota ())
     return QUOTEXC;
   else
     /* #### Should we return `res' here?  */
index 24de9bb8f9d58a8d03329503ca00d54f97298fa7..37b9872451e703fba363ff5cc0bb41d71ab0d723 100644 (file)
@@ -1223,7 +1223,7 @@ The sizes do not match (local %ld) -- retrieving.\n"), local_size);
                         tms, u->url, hstat.len, hstat.contlen, locf, count);
            }
          ++opt.numurls;
-         opt.downloaded += hstat.len;
+         downloaded_increase (hstat.len);
 
          /* Remember that we downloaded the file for later ".orig" code. */
          if (*dt & ADDED_HTML_EXTENSION)
@@ -1249,7 +1249,7 @@ The sizes do not match (local %ld) -- retrieving.\n"), local_size);
                             tms, u->url, hstat.len, locf, count);
                }
              ++opt.numurls;
-             opt.downloaded += hstat.len;
+             downloaded_increase (hstat.len);
 
              /* Remember that we downloaded the file for later ".orig" code. */
              if (*dt & ADDED_HTML_EXTENSION)
@@ -1278,7 +1278,7 @@ The sizes do not match (local %ld) -- retrieving.\n"), local_size);
                         "%s URL:%s [%ld/%ld] -> \"%s\" [%d]\n",
                         tms, u->url, hstat.len, hstat.contlen, locf, count);
              ++opt.numurls;
-             opt.downloaded += hstat.len;
+             downloaded_increase (hstat.len);
 
              /* Remember that we downloaded the file for later ".orig" code. */
              if (*dt & ADDED_HTML_EXTENSION)
index 3bb6b14f5c92445e0fdfcc6b8c87597e52ae7f63..956b94852321df873e1c04c3c3549f20aa93f1c8 100644 (file)
@@ -771,10 +771,12 @@ Can't timestamp and not clobber old files at the same time.\n"));
     {
       logprintf (LOG_NOTQUIET,
                 _("\nFINISHED --%s--\nDownloaded: %s bytes in %d files\n"),
-                time_str (NULL), legible_very_long (opt.downloaded),
+                time_str (NULL),
+                (opt.downloaded_overflow ?
+                 "<overflow>" : legible_very_long (opt.downloaded)),
                 opt.numurls);
       /* Print quota warning, if exceeded.  */
-      if (opt.quota && opt.downloaded > opt.quota)
+      if (downloaded_exceeds_quota ())
        logprintf (LOG_NOTQUIET,
                   _("Download quota (%s bytes) EXCEEDED!\n"),
                   legible (opt.quota));
index a11de0e4e88fdc892a7606f562f848ab33665547..742c75470e453e633f7b960517ab85e79739b360 100644 (file)
@@ -105,6 +105,7 @@ struct options
   long quota;                  /* Maximum number of bytes to
                                   retrieve. */
   VERY_LONG_TYPE downloaded;   /* How much we downloaded already. */
+  int downloaded_overflow;     /* Whether the above overflowed. */
   int numurls;                 /* Number of successfully downloaded
                                   URLs */
 
index 91a8fed0691506c8a464f505c828c8c3429d7305..0e7a7f0dcc86fe365ff29d40e53defc984b0b6cd 100644 (file)
@@ -127,7 +127,7 @@ recursive_retrieve (const char *file, const char *this_url)
   assert (this_url != NULL);
   assert (file != NULL);
   /* If quota was exceeded earlier, bail out.  */
-  if (opt.quota && (opt.downloaded > opt.quota))
+  if (downloaded_exceeds_quota ())
     return QUOTEXC;
   /* Cache the current URL in the list.  */
   if (first_time)
@@ -198,7 +198,7 @@ recursive_retrieve (const char *file, const char *this_url)
   for (cur_url = url_list; cur_url; cur_url = cur_url->next)
     {
       /* If quota was exceeded earlier, bail out.  */
-      if (opt.quota && (opt.downloaded > opt.quota))
+      if (downloaded_exceeds_quota ())
        break;
       /* Parse the URL for convenient use in other functions, as well
         as to get the optimized form.  It also checks URL integrity.  */
@@ -496,7 +496,7 @@ recursive_retrieve (const char *file, const char *this_url)
   FREE_MAYBE (canon_this_url);
   /* Decrement the recursion depth.  */
   --depth;
-  if (opt.quota && (opt.downloaded > opt.quota))
+  if (downloaded_exceeds_quota ())
     return QUOTEXC;
   else
     return RETROK;
index 71017761bfa85731279c929dbf3e276eb35296dc..5f9327a3d75f292166f3dba3243f42e4282813b4 100644 (file)
@@ -534,7 +534,7 @@ retrieve_from_file (const char *file, int html, int *count)
       char *filename, *new_file;
       int dt;
 
-      if (opt.quota && opt.downloaded > opt.quota)
+      if (downloaded_exceeds_quota ())
        {
          status = QUOTEXC;
          break;
@@ -571,3 +571,37 @@ printwhat (int n1, int n2)
 {
   logputs (LOG_VERBOSE, (n1 == n2) ? _("Giving up.\n\n") : _("Retrying.\n\n"));
 }
+
+/* Increment opt.downloaded by BY_HOW_MUCH.  If an overflow occurs,
+   set opt.downloaded_overflow to 1. */
+void
+downloaded_increase (unsigned long by_how_much)
+{
+  VERY_LONG_TYPE old;
+  if (opt.downloaded_overflow)
+    return;
+  old = opt.downloaded;
+  opt.downloaded += by_how_much;
+  if (opt.downloaded < old)    /* carry flag, where are you when I
+                                   need you? */
+    {
+      /* Overflow. */
+      opt.downloaded_overflow = 1;
+      opt.downloaded = ~((VERY_LONG_TYPE)0);
+    }
+}
+
+/* Return non-zero if the downloaded amount of bytes exceeds the
+   desired quota.  If quota is not set or if the amount overflowed, 0
+   is returned. */
+int
+downloaded_exceeds_quota (void)
+{
+  if (!opt.quota)
+    return 0;
+  if (opt.downloaded_overflow)
+    /* We don't really no.  (Wildly) assume not. */
+    return 0;
+
+  return opt.downloaded > opt.quota;
+}
index 5c96ad82a5809dbea3570826ff155eeefd5324fe..308eeedf90147f87b6e2c95ade2ff4e5c7233c8e 100644 (file)
@@ -34,4 +34,7 @@ char *rate PARAMS ((long, long));
 
 void printwhat PARAMS ((int, int));
 
+void downloaded_increase PARAMS ((unsigned long));
+int downloaded_exceeds_quota PARAMS ((void));
+
 #endif /* RETR_H */
index 5dd71d21cde23a4ca4108a0dbd459ca63efe3cef..aa27bc41d3358b1a4b49956ff5c0ec3d1a8c6880 100644 (file)
@@ -210,7 +210,7 @@ enum
   HEAD_ONLY            = 0x0004,       /* only send the HEAD request */
   SEND_NOCACHE         = 0x0008,       /* send Pragma: no-cache directive */
   ACCEPTRANGES         = 0x0010,       /* Accept-ranges header was found */
-  ADDED_HTML_EXTENSION = 0x0020,        /* added ".html" extension due to -E */
+  ADDED_HTML_EXTENSION = 0x0020         /* added ".html" extension due to -E */
 };
 
 /* Universal error type -- used almost everywhere.