El 09/11/17 a las 09:29, Arthur Zakirov escribió:
> Hello,
> 
> On Sun, Oct 01, 2017 at 04:49:17PM -0300, Martin Marques wrote:
>> Updated patch with documentation of the new option.
>>
> 
> I have checked the patch.
> The patch is applied and compiled correctly without any errors. Tests passed.
> The documentation doesn't have errors too.
> 
> 
> I have a little suggestion. Maybe insert new line without any additional 
> parameters? We can check that stderr is not terminal using isatty().
> 
> The code could become:
> 
> if (!isatty(fileno(stderr)))
>       fprintf(stderr, "\n");
> else
>       fprintf(stderr, "\r");
> 
> Also it could be good to not insert new line after progress:
> 
> if (showprogress)
> {
>       progress_report(PQntuples(res), NULL, true);
>       /* if (!batchmode) */
>       /* or */
>       if (isatty(fileno(stderr)))
>               fprintf(stderr, "\n");  /* Need to move to next line */
> }


New version of patch, without the --batch-mode option and using isatty()

I send in a separate thread a proposal to make isatty() be defined as
_isatty() in windows.


-- 
Martín Marqués                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
new file mode 100644
index a8715d9..575a4f9
*** a/src/bin/pg_basebackup/pg_basebackup.c
--- b/src/bin/pg_basebackup/pg_basebackup.c
*************** progress_report(int tablespacenum, const
*** 811,817 ****
  				totaldone_str, totalsize_str, percent,
  				tablespacenum, tablespacecount);
  
! 	fprintf(stderr, "\r");
  }
  
  static int32
--- 811,820 ----
  				totaldone_str, totalsize_str, percent,
  				tablespacenum, tablespacecount);
  
! 	if (!isatty(fileno(stderr)))
! 		fprintf(stderr, "\n");
! 	else
! 		fprintf(stderr, "\r");
  }
  
  static int32
*************** BaseBackup(void)
*** 1796,1802 ****
  				progname);
  
  	if (showprogress && !verbose)
! 		fprintf(stderr, "waiting for checkpoint\r");
  
  	basebkp =
  		psprintf("BASE_BACKUP LABEL '%s' %s %s %s %s %s %s",
--- 1799,1811 ----
  				progname);
  
  	if (showprogress && !verbose)
! 	{
! 		fprintf(stderr, "waiting for checkpoint");
! 		if (isatty(fileno(stderr)))
! 			fprintf(stderr, "\n");
! 		else
! 			fprintf(stderr, "\r");
! 	}
  
  	basebkp =
  		psprintf("BASE_BACKUP LABEL '%s' %s %s %s %s %s %s",
*************** BaseBackup(void)
*** 1929,1935 ****
  	if (showprogress)
  	{
  		progress_report(PQntuples(res), NULL, true);
! 		fprintf(stderr, "\n");	/* Need to move to next line */
  	}
  
  	PQclear(res);
--- 1938,1945 ----
  	if (showprogress)
  	{
  		progress_report(PQntuples(res), NULL, true);
! 		if (isatty(fileno(stderr)))
! 			fprintf(stderr, "\n");	/* Need to move to next line */
  	}
  
  	PQclear(res);

Reply via email to