]> sjero.net Git - wget/blobdiff - src/http.c
Move duplicated code in http.c to a function
[wget] / src / http.c
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;
     }