From 888c30ba01f2ea7fe4ba1f24b536aafe887b2c37 Mon Sep 17 00:00:00 2001 From: Joao Ferreira Date: Wed, 14 May 2008 22:10:37 +0100 Subject: [PATCH 1/4] Fixed bug #23238: --no-clobber doesn't work with -O flag "wget -nc -O file URL" now checks if "file" exists first. If it does, it terminates. --- src/ftp.c | 4 +++- src/http.c | 10 ++++++---- src/main.c | 6 ++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/ftp.c b/src/ftp.c index 5a9ecc6a..e6163880 100644 --- 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); diff --git a/src/http.c b/src/http.c index 129359ca..fa83ebf5 100644 --- a/src/http.c +++ b/src/http.c @@ -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); diff --git a/src/main.c b/src/main.c index 421a5501..fdf368a5 100644 --- a/src/main.c +++ b/src/main.c @@ -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) From 38243f993cebe54a0cdbc7499a4ef9a3484c8d5a Mon Sep 17 00:00:00 2001 From: Joao Ferreira Date: Wed, 14 May 2008 22:18:32 +0100 Subject: [PATCH 2/4] Updated Changelog --- ChangeLog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ChangeLog b/ChangeLog index 166fd30e..ad4c460c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-05-14 Joao Ferreira + + * src/main.c, src/http.c, src/ftp.c: -nc is now working in + conjunction with '-O file'. + 2008-05-12 Micah Cowan * NEWS: Translations and -N/-O. From 9fa15c310f6a676812474c02e00178f4efd7d194 Mon Sep 17 00:00:00 2001 From: Joao Ferreira Date: Wed, 14 May 2008 23:21:06 +0100 Subject: [PATCH 3/4] Changed some comments related with bug fix #23238, to make things clearer. --- src/ftp.c | 2 +- src/http.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ftp.c b/src/ftp.c index e6163880..3223ea59 100644 --- a/src/ftp.c +++ b/src/ftp.c @@ -1092,7 +1092,7 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con) con->target = url_file_name (u); /* If the output_document was given, then this check was already done and - the file doesn't exist. Hence the !opt.output_document */ + the file didn't exist. Hence the !opt.output_document */ if (opt.noclobber && !opt.output_document && file_exists_p (con->target)) { logprintf (LOG_VERBOSE, diff --git a/src/http.c b/src/http.c index fa83ebf5..20f0619a 100644 --- a/src/http.c +++ b/src/http.c @@ -1825,7 +1825,7 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy) { /* 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 doesn't exist. Hence the !opt.output_document */ + 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"), hs->local_file); /* If the file is there, we suppose it's retrieved OK. */ @@ -2379,7 +2379,7 @@ http_loop (struct url *u, char **newloc, char **local_file, const char *referer, { /* 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 doesn't exist. Hence the !opt.output_document */ + 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"), hstat.local_file); From da51f9b2c41ca5f7de5ef3c6d6b8fd5fb2a8142b Mon Sep 17 00:00:00 2001 From: Micah Cowan Date: Thu, 15 May 2008 22:26:00 -0700 Subject: [PATCH 4/4] Fix file-checking in FTP with --spider. --- src/ChangeLog | 5 +++++ src/ftp.c | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index b8b466c0..149bc521 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2008-05-15 Steven Schubiger + + * ftp.c (getftp): Verify that the file actually exists in FTP, by + checking it against the listing. + 2008-05-12 Micah Cowan * main.c (main): Downgrade "-N with -O" to a warning, and switch diff --git a/src/ftp.c b/src/ftp.c index 3223ea59..5bfd2aa8 100644 --- a/src/ftp.c +++ b/src/ftp.c @@ -227,6 +227,8 @@ print_length (wgint size, wgint start, bool authoritative) logputs (LOG_VERBOSE, !authoritative ? _(" (unauthoritative)\n") : "\n"); } +static uerr_t ftp_get_listing (struct url *, ccon *, struct fileinfo **); + /* Retrieves a file with denoted parameters through opening an FTP connection to the server. It always closes the data connection, and closes the control connection in case of error. */ @@ -776,12 +778,37 @@ Error in server response, closing control connection.\n")); if (cmd & DO_RETR) { - /* If we're in spider mode, don't really retrieve anything. The - fact that we got to this point should be proof enough that - the file exists, vaguely akin to HTTP's concept of a "HEAD" - request. */ + /* If we're in spider mode, don't really retrieve anything except + the directory listing and verify whether the given "file" exists. */ if (opt.spider) { + bool exists = false; + uerr_t res; + struct fileinfo *f; + res = ftp_get_listing (u, con, &f); + /* Set the DO_RETR command flag again, because it gets unset when + calling ftp_get_listing() and would otherwise cause an assertion + failure earlier on when this function gets repeatedly called + (e.g., when recursing). */ + con->cmd |= DO_RETR; + if (res == RETROK) + { + while (f) + { + if (!strcmp (f->name, u->file)) + { + exists = true; + break; + } + f = f->next; + } + if (!exists) + { + logputs (LOG_VERBOSE, "\n"); + logprintf (LOG_NOTQUIET, _("No such file `%s'.\n"), + escnonprint (u->file)); + } + } fd_close (csock); con->csock = -1; fd_close (dtsock);