]> sjero.net Git - wget/blobdiff - src/http.c
Ugly fix to make -nc without --content-disposition go back to not fetching files.
[wget] / src / http.c
index 1729b5cbccd30cb0aff822b7766aceb63c7eea5a..02645724b136bc0f5554b9e98489e38aacfbdc68 100644 (file)
@@ -864,8 +864,11 @@ parse_content_range (const char *hdr, wgint *first_byte_ptr,
     return false;
   *last_byte_ptr = num;
   ++hdr;
-  for (num = 0; c_isdigit (*hdr); hdr++)
-    num = 10 * num + (*hdr - '0');
+  if (*hdr == '*')
+    num = -1;
+  else
+    for (num = 0; c_isdigit (*hdr); hdr++)
+      num = 10 * num + (*hdr - '0');
   *entity_length_ptr = num;
   return true;
 }
@@ -2052,7 +2055,10 @@ File `%s' already there; not retrieving.\n\n"), hs->local_file);
       wgint first_byte_pos, last_byte_pos, entity_length;
       if (parse_content_range (hdrval, &first_byte_pos, &last_byte_pos,
                                &entity_length))
-        contrange = first_byte_pos;
+        {
+          contrange = first_byte_pos;
+          contlen = last_byte_pos - first_byte_pos + 1;
+        }
     }
   resp_free (resp);
 
@@ -2152,7 +2158,10 @@ File `%s' already there; not retrieving.\n\n"), hs->local_file);
       CLOSE_INVALIDATE (sock);
       return RANGEERR;
     }
-  hs->contlen = contlen + contrange;
+  if (contlen == -1)
+    hs->contlen = -1;
+  else
+    hs->contlen = contlen + contrange;
 
   if (opt.verbose)
     {
@@ -2350,6 +2359,26 @@ http_loop (struct url *u, char **newloc, char **local_file, const char *referer,
       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)
+    {
+      /* If opt.noclobber is turned on and file already exists, do not
+         retrieve the file */
+      logprintf (LOG_VERBOSE, _("\
+File `%s' already there; not retrieving.\n\n"), 
+                 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;
+
+      return RETRUNNEEDED;
+    }
+
   /* Reset the counter. */
   count = 0;