diff options
Diffstat (limited to 'programs')
-rw-r--r-- | programs/gvfs-copy.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/programs/gvfs-copy.c b/programs/gvfs-copy.c index 7a61dcf8..14d569cc 100644 --- a/programs/gvfs-copy.c +++ b/programs/gvfs-copy.c @@ -65,22 +65,34 @@ is_dir (GFile *file) return res; } -static GTimeVal start_time; +static gint64 start_time; +static gint64 previous_time; static void show_progress (goffset current_num_bytes, goffset total_num_bytes, gpointer user_data) { - GTimeVal tv; - char *size; - - g_get_current_time (&tv); - - size = g_format_size (current_num_bytes / MAX (tv.tv_sec - start_time.tv_sec, 1)); - g_print (_("progress")); - g_print (" %"G_GINT64_FORMAT"/%"G_GINT64_FORMAT" (%s/s)\n", - current_num_bytes, total_num_bytes, size); - g_free (size); + gint64 tv; + char *current_size, *total_size, *rate; + + tv = g_get_monotonic_time (); + if (tv - previous_time < (G_USEC_PER_SEC / 5) && + current_num_bytes != total_num_bytes) + return; + + current_size = g_format_size (current_num_bytes); + total_size = g_format_size (total_num_bytes); + rate = g_format_size (current_num_bytes / + MAX ((tv - start_time) / G_USEC_PER_SEC, 1)); + g_print ("\r\033[K"); + g_print (_("Transferred %s out of %s (%s/s)"), + current_size, total_size, rate); + + previous_time = tv; + + g_free (current_size); + g_free (total_size); + g_free (rate); } static void @@ -195,7 +207,7 @@ main (int argc, char *argv[]) error = NULL; - g_get_current_time (&start_time); + start_time = g_get_monotonic_time (); if (!g_file_copy (source, target, flags, NULL, progress?show_progress:NULL, NULL, &error)) { if (interactive && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) @@ -225,6 +237,8 @@ main (int argc, char *argv[]) retval = 1; } } + if (progress && retval == 0) + g_print("\n"); g_object_unref (source); g_object_unref (target); |