mkfs.erofs is noisy when run with a pipe attached to stdout/stderr
Hi,
When executed with a pipe attached to stdout/stderr (for example in CI), mkfs.erofs is super verbose as \r doesn't go to the beginning of the line so mkfs.erofs will print a separate line for each file in the root directory that is passed to mkfs.erofs. Could mkfs.erofs be updated to not print a separate line for each file when stdout/stderr are not ttys?
Cheers,
Daan De Meyer
Hi Daan,
Quoted 8 lines · Daan De Meyer
Hi,
When executed with a pipe attached to stdout/stderr (for example in CI), mkfs.erofs is super verbose as \r doesn't go to the beginning of the line so mkfs.erofs will print a separate line for each file in the root directory that is passed to mkfs.erofs. Could mkfs.erofs be updated to not print a separate line for each file when stdout/stderr are not ttys?
Thanks for the report. It's helpful and let me investigate and fix the non-tty cases.
Thanks,
Gao Xiang
Quoted 4 lines
Cheers,
Daan De Meyer
PATCH 1/1 erofs-utils: avoid noisy prints if stdout is not a tty
In reply to Daan De MeyerAs Daan reported, "mkfs.erofs is super verbose as \r doesn't go to the beginning of the line". Don't print messages like this if stdout is not a tty.
--- lib/config.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-)
lib/config.c +23 -10
@@ -7,6 +7,7 @@#include <string.h> #include <stdlib.h> #include <stdarg.h> +#include <unistd.h> #include "erofs/print.h" #include "erofs/internal.h" #include "liberofs_private.h"
@@ -16,6 +17,7 @@struct erofs_configure cfg;struct erofs_sb_info sbi; +bool erofs_stdout_tty;void erofs_init_configure (void ) {
@@ -33,6 +35,8 @@ void erofs_init_configure(void) cfg.c_pclusterblks_max =1 ; cfg.c_pclusterblks_def =1 ; cfg.c_max_decompressed_extent_bytes =-1 ; + + erofs_stdout_tty =isatty (STDOUT_FILENO ); }void erofs_show_config (void )
@@ -107,15 +111,19 @@ char *erofs_trim_for_progressinfo(const char *str, int placeholder) {int col, len; +if (!erofs_stdout_tty) { +return strdup (str); + }else {#ifdef GWINSZ_IN_SYS_IOCTL -struct winsize winsize; +struct winsize winsize; -if (ioctl (1 ,TIOCGWINSZ , &winsize) >=0 && - winsize.ws_col >0 ) - col = winsize.ws_col; - else +if (ioctl (STDOUT_FILENO ,TIOCGWINSZ , &winsize) >=0 && + winsize.ws_col >0 ) + col = winsize.ws_col; + else#endif - col =80 ; + col =80 ; + }if (col <= placeholder)return strdup ("" );
@@ -140,7 +148,7 @@ void erofs_msg(int dbglv, const char *fmt, ...)FILE *f = dbglv >=EROFS_ERR ? stderr : stdout;if (__erofs_is_progressmsg) { -fputc ('\n' , f); +fputc ('\n' , stdout); __erofs_is_progressmsg = false; }va_start (ap, fmt);
@@ -160,7 +168,12 @@ void erofs_update_progressinfo(const char *fmt, ...)vsprintf (msg, fmt, ap);va_end (ap); -printf ("\r\033[K%s" , msg); - __erofs_is_progressmsg = true; -fflush (stdout); +if (erofs_stdout_tty) { +printf ("\r\033[K%s" , msg); + __erofs_is_progressmsg = true; +fflush (stdout); +return ; + } +fputs (msg, stdout); +fputc ('\n' , stdout); }
Signature · 1 line
2.39.3