]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_cb_prg: make resumed upload progress bar show better
authorDaniel Stenberg <daniel@haxx.se>
Mon, 27 Sep 2021 07:13:40 +0000 (09:13 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 27 Sep 2021 21:17:44 +0000 (23:17 +0200)
This is a regression that was *probably* injected in the larger progress
bar overhaul in 2018.

Reported-by: beslick5 on github
Fixes #7760
Closes #7777

src/tool_cb_prg.c

index bb93d15f822d63b5aaea2feaf8361303405d13cc..2a23fd91174b5da240407efc6f3ba693a515f10f 100644 (file)
@@ -125,9 +125,6 @@ int tool_progress_cb(void *clientp,
                      curl_off_t dltotal, curl_off_t dlnow,
                      curl_off_t ultotal, curl_off_t ulnow)
 {
-  /* The original progress-bar source code was written for curl by Lars Aas,
-     and this new edition inherits some of his concepts. */
-
   struct timeval now = tvnow();
   struct per_transfer *per = clientp;
   struct OperationConfig *config = per->config;
@@ -135,19 +132,28 @@ int tool_progress_cb(void *clientp,
   curl_off_t total;
   curl_off_t point;
 
-  /* Calculate expected transfer size. initial_size can be less than zero
-     when indicating that we are expecting to get the filesize from the
-     remote */
-  if(bar->initial_size < 0 ||
-     ((CURL_OFF_T_MAX - bar->initial_size) < (dltotal + ultotal)))
+  /* Calculate expected transfer size. initial_size can be less than zero when
+     indicating that we are expecting to get the filesize from the remote */
+  if(bar->initial_size < 0) {
+    if(dltotal || ultotal)
+      total = dltotal + ultotal;
+    else
+      total = CURL_OFF_T_MAX;
+  }
+  else if((CURL_OFF_T_MAX - bar->initial_size) < (dltotal + ultotal))
     total = CURL_OFF_T_MAX;
   else
     total = dltotal + ultotal + bar->initial_size;
 
   /* Calculate the current progress. initial_size can be less than zero when
      indicating that we are expecting to get the filesize from the remote */
-  if(bar->initial_size < 0 ||
-     ((CURL_OFF_T_MAX - bar->initial_size) < (dlnow + ulnow)))
+  if(bar->initial_size < 0) {
+    if(dltotal || ultotal)
+      point = dlnow + ulnow;
+    else
+      point = CURL_OFF_T_MAX;
+  }
+  else if((CURL_OFF_T_MAX - bar->initial_size) < (dlnow + ulnow))
     point = CURL_OFF_T_MAX;
   else
     point = dlnow + ulnow + bar->initial_size;
@@ -215,9 +221,8 @@ void progressbarinit(struct ProgressData *bar,
   char *colp;
   memset(bar, 0, sizeof(struct ProgressData));
 
-  /* pass this through to progress function so
-   * it can display progress towards total file
-   * not just the part that's left. (21-may-03, dbyron) */
+  /* pass the resume from value through to the progress function so it can
+   * display progress towards total file not just the part that's left. */
   if(config->use_resume)
     bar->initial_size = config->resume_from;