Dear Wget,

Based on the changes in commit
d6d00006a0c446f91a005d44ab72eb956c58ad2d, I have made a patch,
attached, to add an option to retry on host errors.

It has been requested a few times (links at end of email), and just
now it frustrated me, so I think it is a good option to have.

The patch does not affect the default behavior.

Thank you for your consideration!

—Elliot


P. S.: Links to show value of patch, where this has been requested and
impractical workarounds suggested instead:

https://stackoverflow.com/questions/30983511/wget-force-retry-until-there-is-a-connection

https://bugzilla.redhat.com/show_bug.cgi?id=202956

https://ubuntuforums.org/showthread.php?t=1397043
From ff81ecaf180fd3309e5836ebe13e42396b6599fb Mon Sep 17 00:00:00 2001
From: ethus3h <kolu...@gmail.com>
Date: Sun, 10 Jun 2018 23:23:09 -0400
Subject: [PATCH] Add option to retry on host errors

---
 doc/wget.texi |  4 ++++
 src/http.c    | 13 ++++++++++++-
 src/init.c    |  1 +
 src/main.c    |  1 +
 src/options.h |  1 +
 5 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/doc/wget.texi b/doc/wget.texi
index eaf6b380..38b4a245 100644
--- a/doc/wget.texi
+++ b/doc/wget.texi
@@ -1750,6 +1750,10 @@ some few obscure servers, which never send HTTP authentication
 challenges, but accept unsolicited auth info, say, in addition to
 form-based authentication.
 
+@item --retry-on-host-error
+Consider host errors, such as ``Temporary failure in name resolution'',
+as non-fatal, transient errors.
+
 @item --retry-on-http-error=@var{code[,code,...]}
 Consider given HTTP response codes as non-fatal, transient errors.
 Supply a comma-separated list of 3-digit HTTP response codes as
diff --git a/src/http.c b/src/http.c
index 77bdbbed..bb52218f 100644
--- a/src/http.c
+++ b/src/http.c
@@ -4386,7 +4386,18 @@ http_loop (const struct url *u, struct url *original_url, char **newloc,
           logputs (LOG_VERBOSE, "\n");
           logprintf (LOG_NOTQUIET, _("Cannot write to %s (%s).\n"),
                      quote (hstat.local_file), strerror (errno));
-        case HOSTERR: case CONIMPOSSIBLE: case PROXERR: case SSLINITFAILED:
+        case HOSTERR:
+          /* Fatal unless option set otherwise. */
+          if ( opt.retry_on_host_error )
+            {
+              printwhat (count, opt.ntry);
+              xfree (hstat.message);
+              xfree (hstat.error);
+              continue;
+            }
+          ret = err;
+          goto exit;
+        case CONIMPOSSIBLE: case PROXERR: case SSLINITFAILED:
         case CONTNOTSUPPORTED: case VERIFCERTERR: case FILEBADFILE:
         case UNKNOWNATTR:
           /* Fatal errors just return from the function.  */
diff --git a/src/init.c b/src/init.c
index eb81ab47..bb82b329 100644
--- a/src/init.c
+++ b/src/init.c
@@ -313,6 +313,7 @@ static const struct {
   { "restrictfilenames", NULL,                  cmd_spec_restrict_file_names },
   { "retrsymlinks",     &opt.retr_symlinks,     cmd_boolean },
   { "retryconnrefused", &opt.retry_connrefused, cmd_boolean },
+  { "retryonhosterror", &opt.retry_on_host_error, cmd_boolean },
   { "retryonhttperror", &opt.retry_on_http_error, cmd_string },
   { "robots",           &opt.use_robots,        cmd_boolean },
   { "savecookies",      &opt.cookies_output,    cmd_file },
diff --git a/src/main.c b/src/main.c
index 73b7baee..e731f3aa 100644
--- a/src/main.c
+++ b/src/main.c
@@ -420,6 +420,7 @@ static struct cmdline_option option_data[] =
     { "restrict-file-names", 0, OPT_BOOLEAN, "restrictfilenames", -1 },
     { "retr-symlinks", 0, OPT_BOOLEAN, "retrsymlinks", -1 },
     { "retry-connrefused", 0, OPT_BOOLEAN, "retryconnrefused", -1 },
+    { "retry-on-host-error", 0, OPT_BOOLEAN, "retryonhosterror", -1 },
     { "retry-on-http-error", 0, OPT_VALUE, "retryonhttperror", -1 },
     { "save-cookies", 0, OPT_VALUE, "savecookies", -1 },
     { "save-headers", 0, OPT_BOOLEAN, "saveheaders", -1 },
diff --git a/src/options.h b/src/options.h
index cf4dec88..19d93f14 100644
--- a/src/options.h
+++ b/src/options.h
@@ -41,6 +41,7 @@ struct options
   bool quiet;                   /* Are we quiet? */
   int ntry;                     /* Number of tries per URL */
   bool retry_connrefused;       /* Treat CONNREFUSED as non-fatal. */
+  bool retry_on_host_error;     /* Treat host errors as non-fatal. */
   char *retry_on_http_error;    /* Treat given HTTP errors as non-fatal. */
   bool background;              /* Whether we should work in background. */
   bool ignore_length;           /* Do we heed content-length at all?  */
-- 
2.16.1

Reply via email to