From 94c4d07011fe20570d5984e7157e154bc2db9b4d Mon Sep 17 00:00:00 2001
From: Yousong Zhou <yszhou4tech@gmail.com>
Date: Thu, 16 Oct 2014 15:16:53 +0800
Subject: [PATCH 5/5] Fix --content-on-error option handling.

 - Log --content-on-error downloads.
 - Let --convert-links also work with --content-on-error.
 - Preserve exit code WGET_EXIT_SERVER_ERROR (8) when for server error.
---
 src/http.c | 6 +++---
 src/retr.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/http.c b/src/http.c
index bc2cfd0..1c5e99d 100644
--- a/src/http.c
+++ b/src/http.c
@@ -3513,7 +3513,7 @@ Remote file exists.\n\n"));
 
       if (hstat.len == hstat.contlen)
         {
-          if (*dt & RETROKF)
+          if (*dt & RETROKF || opt.content_on_error)
             {
               bool write_to_stdout = (opt.output_document && HYPHENP (opt.output_document));
 
@@ -3549,7 +3549,7 @@ Remote file exists.\n\n"));
           if (hstat.contlen == -1)  /* We don't know how much we were supposed
                                        to get, so assume we succeeded. */
             {
-              if (*dt & RETROKF)
+              if (*dt & RETROKF || opt.content_on_error)
                 {
                   bool write_to_stdout = (opt.output_document && HYPHENP (opt.output_document));
 
@@ -3627,7 +3627,7 @@ Remote file exists.\n\n"));
   while (!opt.ntry || (count < opt.ntry));
 
 exit:
-  if (ret == RETROK && local_file)
+  if ((ret == RETROK || opt.content_on_error) && local_file)
     {
       xfree (*local_file);
       *local_file = xstrdup (hstat.local_file);
diff --git a/src/retr.c b/src/retr.c
index f12c50f..d8626db 100644
--- a/src/retr.c
+++ b/src/retr.c
@@ -941,7 +941,7 @@ retrieve_url (struct url * orig_parsed, const char *origurl, char **file,
           DEBUGP (("[Couldn't fallback to non-utf8 for %s\n", quote (url)));
     }
 
-  if (local_file && u && *dt & RETROKF)
+  if (local_file && u && (*dt & RETROKF || opt.content_on_error))
     {
       register_download (u->url, local_file);
 
-- 
2.2.1

