]> sjero.net Git - wget/commitdiff
Move duplicated code in http.c to a function
authorSteven Schubiger <stsc@member.fsf.org>
Wed, 23 Feb 2011 09:37:48 +0000 (10:37 +0100)
committerGiuseppe Scrivano <gscrivano@gnu.org>
Wed, 23 Feb 2011 09:37:48 +0000 (10:37 +0100)
src/ChangeLog
src/http.c

index 91f4f033f731b836c15f28d7299875ce2939834e..7f79edb8b47115ab5890d1cd49b07e456b3759c1 100644 (file)
@@ -1,3 +1,9 @@
+2011-02-22  Steven Schubiger  <stsc@member.fsf.org>
+
+       * http.c (gethttp, http_loop): Move duplicated code which is run
+       when an existing file is not to be clobbered to a function.
+       (get_file_flags): New static function.
+
 2010-12-10  Evgeniy Philippov <egphilippov@googlemail.com> (tiny change)
 
        * main.c (main): Initialize `total_downloaded_bytes'.
index 142b9219442a8c5f2888ac8bea9edb76910786d0..b4f1667b6e597b0bf6972a0466e658b3bda3a6ef 100644 (file)
@@ -1448,6 +1448,20 @@ free_hstat (struct http_stat *hs)
   hs->error = NULL;
 }
 
+static void
+get_file_flags (const char *filename, int *dt)
+{
+  logprintf (LOG_VERBOSE, _("\
+File %s already there; not retrieving.\n\n"), quote (filename));
+  /* If the file is there, we suppose it's retrieved OK.  */
+  *dt |= RETROKF;
+
+  /* #### Bogusness alert.  */
+  /* If its suffix is "html" or "htm" or similar, assume text/html.  */
+  if (has_html_suffix_p (filename))
+    *dt |= TEXTHTML;
+}
+
 #define BEGINS_WITH(line, string_constant)                               \
   (!strncasecmp (line, string_constant, sizeof (string_constant) - 1)    \
    && (c_isspace (line[sizeof (string_constant) - 1])                      \
@@ -2158,16 +2172,7 @@ read_header:
           /* If opt.noclobber is turned on and file already exists, do not
              retrieve the file. But if the output_document was given, then this
              test was already done and the file didn't exist. Hence the !opt.output_document */
-          logprintf (LOG_VERBOSE, _("\
-File %s already there; not retrieving.\n\n"), quote (hs->local_file));
-          /* If the file is there, we suppose it's retrieved OK.  */
-          *dt |= RETROKF;
-
-          /* #### Bogusness alert.  */
-          /* If its suffix is "html" or "htm" or similar, assume text/html.  */
-          if (has_html_suffix_p (hs->local_file))
-            *dt |= TEXTHTML;
-
+          get_file_flags (hs->local_file, dt);
           xfree (head);
           xfree_null (message);
           return RETRUNNEEDED;
@@ -2639,24 +2644,12 @@ http_loop (struct url *u, struct url *original_url, char **newloc,
       got_name = true;
     }
 
-  /* TODO: Ick! This code is now in both gethttp and http_loop, and is
-   * screaming for some refactoring. */
   if (got_name && file_exists_p (hstat.local_file) && opt.noclobber && !opt.output_document)
     {
       /* If opt.noclobber is turned on and file already exists, do not
          retrieve the file. But if the output_document was given, then this
          test was already done and the file didn't exist. Hence the !opt.output_document */
-      logprintf (LOG_VERBOSE, _("\
-File %s already there; not retrieving.\n\n"),
-                 quote (hstat.local_file));
-      /* If the file is there, we suppose it's retrieved OK.  */
-      *dt |= RETROKF;
-
-      /* #### Bogusness alert.  */
-      /* If its suffix is "html" or "htm" or similar, assume text/html.  */
-      if (has_html_suffix_p (hstat.local_file))
-        *dt |= TEXTHTML;
-
+      get_file_flags (hstat.local_file, dt);
       ret = RETROK;
       goto exit;
     }