diff options
Diffstat (limited to 'src/bin/pg_basebackup/pg_basebackup.c')
-rw-r--r-- | src/bin/pg_basebackup/pg_basebackup.c | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index d472f4d1c23..54bf864efde 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -143,7 +143,8 @@ static PQExpBuffer recoveryconfcontents = NULL; /* Function headers */ static void usage(void); static void verify_dir_is_empty_or_create(char *dirname, bool *created, bool *found); -static void progress_report(int tablespacenum, const char *filename, bool force); +static void progress_report(int tablespacenum, const char *filename, bool force, + bool finished); static void ReceiveTarFile(PGconn *conn, PGresult *res, int rownum); static void ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum); @@ -706,11 +707,15 @@ verify_dir_is_empty_or_create(char *dirname, bool *created, bool *found) * Print a progress report based on the global variables. If verbose output * is enabled, also print the current file name. * - * Progress report is written at maximum once per second, unless the - * force parameter is set to true. + * Progress report is written at maximum once per second, unless the force + * parameter is set to true. + * + * If finished is set to true, this is the last progress report. The cursor + * is moved to the next line. */ static void -progress_report(int tablespacenum, const char *filename, bool force) +progress_report(int tablespacenum, const char *filename, + bool force, bool finished) { int percent; char totaldone_str[32]; @@ -721,7 +726,7 @@ progress_report(int tablespacenum, const char *filename, bool force) return; now = time(NULL); - if (now == last_progress_report && !force) + if (now == last_progress_report && !force && !finished) return; /* Max once per second */ last_progress_report = now; @@ -792,10 +797,11 @@ progress_report(int tablespacenum, const char *filename, bool force) totaldone_str, totalsize_str, percent, tablespacenum, tablespacecount); - if (isatty(fileno(stderr))) - fprintf(stderr, "\r"); - else - fprintf(stderr, "\n"); + /* + * Stay on the same line if reporting to a terminal and we're not done + * yet. + */ + fprintf(stderr, (!finished && isatty(fileno(stderr))) ? "\r" : "\n"); } static int32 @@ -1355,9 +1361,9 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum) } } totaldone += r; - progress_report(rownum, filename, false); + progress_report(rownum, filename, false, false); } /* while (1) */ - progress_report(rownum, filename, true); + progress_report(rownum, filename, true, false); if (copybuf != NULL) PQfreemem(copybuf); @@ -1614,7 +1620,7 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum) exit(1); } totaldone += r; - progress_report(rownum, filename, false); + progress_report(rownum, filename, false, false); current_len_left -= r; if (current_len_left == 0 && current_padding == 0) @@ -1630,7 +1636,7 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum) } } /* continuing data in existing file */ } /* loop over all data blocks */ - progress_report(rownum, filename, true); + progress_report(rownum, filename, true, false); if (file != NULL) { @@ -2011,11 +2017,7 @@ BaseBackup(void) } /* Loop over all tablespaces */ if (showprogress) - { - progress_report(PQntuples(res), NULL, true); - if (isatty(fileno(stderr))) - fprintf(stderr, "\n"); /* Need to move to next line */ - } + progress_report(PQntuples(res), NULL, true, true); PQclear(res); |