* Added ETA information to kaoupload progress display.
authorUrban Wallasch <urban.wallasch@freenet.de>
Wed, 19 May 2021 16:40:28 +0000 (18:40 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Wed, 19 May 2021 16:40:28 +0000 (18:40 +0200)
kaoupload.c

index e510bab4a6c2c74e46c03206fe36e858411f3054..8e2443318969a5ead7f5c12be7dc0bbcaf7a7fb7 100644 (file)
@@ -103,6 +103,18 @@ static curl_off_t str_to_bwl( const char *s ) {
     return byps;
 }
 
+static const char *eta_fmt(int s) {
+    static char tbuf[10];
+    int h, m, n = 0;
+    h = s / 3600;
+    m = (s / 60) % 60;
+    s = s % 60;
+    if ( h )
+        n = snprintf(tbuf, sizeof tbuf, "%02d:", h);
+    snprintf(tbuf + n, sizeof tbuf - n, "%02d:%02d", m, s);
+    return tbuf;
+}
+
 static uint64_t time_ms( void ) {
     struct timespec tv;
     clock_gettime( CLOCK_REALTIME, &tv );
@@ -326,6 +338,7 @@ static int upload_file( const char *fn ) {
     starttime = time_ms();
 
     while ( fi.remn ) {
+        int eta;
         if ( gotsig ) {
             res = -1;
             break;
@@ -337,6 +350,8 @@ static int upload_file( const char *fn ) {
         if ( CSIZE_HARDLIMIT < csize )
             csize = CSIZE_HARDLIMIT;
         fprintf( stderr, "\r%3.f%% (%5.1f KiB/s) ", (double)fi.coff * 100 / fi.size, (double)fi.speed / 1024 );
+        eta = (double)fi.remn / (fi.speed ? fi.speed : 1);
+        fprintf( stderr, "  ETA: %s    ", eta_fmt(eta));
         // fprintf( stderr, "[csize: %ld] {offset: %ld} ", (long)csize, (long)fi.coff );
         fflush( stderr );
     }