Whamcloud - gitweb
tests: add test for e2fsck of verity file
[tools/e2fsprogs.git] / lib / ext2fs / progress.c
index 1b9bf9c..83556b1 100644 (file)
  * %End-Header%
  */
 
+#include "config.h"
 #include "ext2fs.h"
 #include "ext2fsP.h"
 
+#include <time.h>
+
 static char spaces[80], backspaces[80];
+static time_t last_update;
+
+struct ext2fs_progress_ops ext2fs_numeric_progress_ops = {
+       .init           = ext2fs_numeric_progress_init,
+       .update         = ext2fs_numeric_progress_update,
+       .close          = ext2fs_numeric_progress_close,
+};
 
 static int int_log10(unsigned int arg)
 {
@@ -41,11 +51,11 @@ void ext2fs_numeric_progress_init(ext2_filsys fs,
        spaces[sizeof(spaces)-1] = 0;
        memset(backspaces, '\b', sizeof(backspaces)-1);
        backspaces[sizeof(backspaces)-1] = 0;
-       progress->skip_progress = 0;
+
+       memset(progress, 0, sizeof(*progress));
        if (getenv("E2FSPROGS_SKIP_PROGRESS"))
                progress->skip_progress++;
 
-       memset(progress, 0, sizeof(*progress));
 
        /*
         * Figure out how many digits we need
@@ -57,16 +67,23 @@ void ext2fs_numeric_progress_init(ext2_filsys fs,
                fputs(label, stdout);
                fflush(stdout);
        }
+       last_update = 0;
 }
 
 void ext2fs_numeric_progress_update(ext2_filsys fs,
                                    struct ext2fs_numeric_progress_struct * progress,
                                    __u64 val)
 {
+       time_t now;
+
        if (!(fs->flags & EXT2_FLAG_PRINT_PROGRESS))
                return;
        if (progress->skip_progress)
                return;
+       now = time(0);
+       if (now == last_update)
+               return;
+       last_update = now;
 
        printf("%*llu/%*llu", progress->log_max, val,
               progress->log_max, progress->max);