/* 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 ReceiveTarCopyChunk(size_t r, char *copybuf, void *callback_data);
* 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];
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;
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
}
}
- progress_report(rownum, state.filename, true);
+ progress_report(rownum, state.filename, true, false);
/*
* Do not sync the resulting tar file yet, all files are synced once at
}
}
totaldone += r;
- progress_report(state->tablespacenum, state->filename, false);
+ progress_report(state->tablespacenum, state->filename, false, false);
}
if (state.file)
fclose(state.file);
- progress_report(rownum, state.filename, true);
+ progress_report(rownum, state.filename, true, false);
if (state.file != NULL)
{
exit(1);
}
totaldone += r;
- progress_report(state->tablespacenum, state->filename, false);
+ progress_report(state->tablespacenum, state->filename, false, false);
state->current_len_left -= r;
if (state->current_len_left == 0 && state->current_padding == 0)
ReceiveBackupManifest(conn);
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);
* src/bin/pg_basebackup/pg_basebackup.c.
*/
static void
-progress_report(bool force)
+progress_report(bool finished)
{
int percent;
char total_size_str[32];
Assert(showprogress);
now = time(NULL);
- if (now == last_progress_report && !force)
+ if (now == last_progress_report && !finished)
return; /* Max once per second */
/* Save current time */
(int) strlen(current_size_str), current_size_str, total_size_str,
percent);
- /* Stay on the same line if reporting to a terminal */
- fprintf(stderr, isatty(fileno(stderr)) ? "\r" : "\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 bool
(void) scan_directory(DataDir, "pg_tblspc", false);
if (showprogress)
- {
progress_report(true);
- fprintf(stderr, "\n"); /* Need to move to next line */
- }
printf(_("Checksum operation completed\n"));
printf(_("Files scanned: %s\n"), psprintf(INT64_FORMAT, files));
executeFileMap();
progress_report(true);
- printf("\n");
if (showprogress)
pg_log_info("creating backup label and updating control file");
/*
* Print a progress report based on the fetch_size and fetch_done variables.
*
- * 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, except that the
+ * last progress report is always printed.
+ *
+ * If finished is set to true, this is the last progress report. The cursor
+ * is moved to the next line.
*/
void
-progress_report(bool force)
+progress_report(bool finished)
{
static pg_time_t last_progress_report = 0;
int percent;
return;
now = time(NULL);
- if (now == last_progress_report && !force)
+ if (now == last_progress_report && !finished)
return; /* Max once per second */
last_progress_report = now;
fprintf(stderr, _("%*s/%s kB (%d%%) copied"),
(int) strlen(fetch_size_str), fetch_done_str, fetch_size_str,
percent);
- 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");
}
/*