From 653a658a581547dbbc0a42315cd6048c50f55c85 Mon Sep 17 00:00:00 2001
From: Micah Cowan <micah@cowan.name>
Date: Sun, 10 Feb 2008 14:39:41 -0800
Subject: [PATCH] Fixed #22251: Terminated download gets new filename.

---
 src/ChangeLog  | 12 ++++++++++++
 src/http.c     |  7 ++++++-
 src/progress.c |  4 ++--
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index c5b2c200..673bd9c7 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,15 @@
+2008-02-10  Micah Cowan  <micah@cowan.name>
+
+	* http.c: Added existence_checked member to the http_stat
+	struct.
+	(gethttp): Mark hs->existence_checked when we've checked whether
+	a file-to-download exists; so we don't check it again if the
+	connection gets lost (and potentially pick a new "unique" name).
+	This fixes bug 22251.
+	* progress.c (create_image): Add space for an extra column in
+	the "eta" portion of the progress bar image; to deal with
+	too-long Czech translation.
+
 2008-02-07  Micah Cowan  <micah@cowan.name>
 
 	* progress.c (create_image): Remove assertion on exceeding
diff --git a/src/http.c b/src/http.c
index 02645724..3a0481a2 100644
--- a/src/http.c
+++ b/src/http.c
@@ -1291,6 +1291,10 @@ struct http_stat
   double dltime;                /* time it took to download the data */
   const char *referer;          /* value of the referer header. */
   char *local_file;             /* local file name. */
+  bool existence_checked;       /* true if we already checked for a file's
+                                   existence after having begun to download
+                                   (needed in gethttp for when connection is
+                                   interrupted/restarted. */
   bool timestamp_checked;       /* true if pre-download time-stamping checks 
                                  * have already been performed */
   char *orig_file_name;         /* name of file to compare for time-stamping
@@ -1807,7 +1811,7 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy)
     }
   
   /* TODO: perform this check only once. */
-  if (file_exists_p (hs->local_file))
+  if (!hs->existence_checked && file_exists_p (hs->local_file))
     {
       if (opt.noclobber)
         {
@@ -1833,6 +1837,7 @@ File `%s' already there; not retrieving.\n\n"), hs->local_file);
           hs->local_file = unique;
         }
     }
+  hs->existence_checked = true;
 
   /* Support timestamping */
   /* TODO: move this code out of gethttp. */
diff --git a/src/progress.c b/src/progress.c
index bbbad179..9ea74b03 100644
--- a/src/progress.c
+++ b/src/progress.c
@@ -874,12 +874,12 @@ create_image (struct bar_progress *bp, double dl_total_time, bool done)
      "[]"              - progress bar decorations - 2 chars
      " nnn,nnn,nnn"    - downloaded bytes         - 12 chars or very rarely more
      " 12.5K/s"        - download rate             - 8 chars
-     "  eta 36m 51s"   - ETA                      - 13 chars
+     "  eta 36m 51s"   - ETA                      - 14 chars
 
      "=====>..."       - progress bar             - the rest
   */
   int dlbytes_size = 1 + MAX (size_grouped_len, 11);
-  int progress_size = bp->width - (4 + 2 + dlbytes_size + 8 + 13);
+  int progress_size = bp->width - (4 + 2 + dlbytes_size + 8 + 14);
 
   if (progress_size < 5)
     progress_size = 0;