]> sjero.net Git - wget/commitdiff
Fixed bug #23238: --no-clobber doesn't work with -O flag
authorJoao Ferreira <joao@joaoff.com>
Wed, 14 May 2008 21:10:37 +0000 (22:10 +0100)
committerJoao Ferreira <joao@joaoff.com>
Wed, 14 May 2008 21:10:37 +0000 (22:10 +0100)
"wget -nc -O file URL" now checks if "file" exists first. If it does, it terminates.

src/ftp.c
src/http.c
src/main.c

index 5a9ecc6a694969a054c1c33560bbfc913b623f20..e6163880ec0c7996cea37c4d2eddeee0e1f3a938 100644 (file)
--- a/src/ftp.c
+++ b/src/ftp.c
@@ -1091,7 +1091,9 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con)
   if (!con->target)
     con->target = url_file_name (u);
 
-  if (opt.noclobber && file_exists_p (con->target))
+  /* If the output_document was given, then this check was already done and
+     the file doesn't exist. Hence the !opt.output_document */
+  if (opt.noclobber && !opt.output_document && file_exists_p (con->target))
     {
       logprintf (LOG_VERBOSE,
                  _("File `%s' already there; not retrieving.\n"), con->target);
index 129359cad47e183a01d89ae1aeb25b32b0a6ee3e..fa83ebf5d8254dacf0c5092d83ef87547e094f59 100644 (file)
@@ -1821,10 +1821,11 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
   /* TODO: perform this check only once. */
   if (!hs->existence_checked && file_exists_p (hs->local_file))
     {
-      if (opt.noclobber)
+      if (opt.noclobber && !opt.output_document)
         {
           /* If opt.noclobber is turned on and file already exists, do not
-             retrieve the file */
+             retrieve the file. But if the output_document was given, then this
+             test was already done and the file doesn't exist. Hence the !opt.output_document */
           logprintf (LOG_VERBOSE, _("\
 File `%s' already there; not retrieving.\n\n"), hs->local_file);
           /* If the file is there, we suppose it's retrieved OK.  */
@@ -2374,10 +2375,11 @@ http_loop (struct url *u, char **newloc, char **local_file, const char *referer,
 
   /* 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 (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 */
+         retrieve the file. But if the output_document was given, then this
+         test was already done and the file doesn't exist. Hence the !opt.output_document */
       logprintf (LOG_VERBOSE, _("\
 File `%s' already there; not retrieving.\n\n"), 
                  hstat.local_file);
index 421a5501b6e34e4795a9a62e779289e42aff1a2f..fdf368a51fc2e897e9fc2e236a8d5e9744bea2f5 100644 (file)
@@ -905,6 +905,12 @@ WARNING: timestamping does nothing in combination with -O. See the manual\n\
 for details.\n\n"));
           opt.timestamping = false;
         }
+      if (opt.noclobber && file_exists_p(opt.output_document)) 
+           { 
+              /* Check if output file exists; if it does, exit. */
+              logprintf (LOG_VERBOSE, _("File `%s' already there; not retrieving.\n"), opt.output_document);
+              exit(1);
+           }  
     }
 
   if (!nurl && !opt.input_filename)