summaryrefslogtreecommitdiff
path: root/src/bin/pg_upgrade/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/pg_upgrade/util.c')
-rw-r--r--src/bin/pg_upgrade/util.c61
1 files changed, 50 insertions, 11 deletions
diff --git a/src/bin/pg_upgrade/util.c b/src/bin/pg_upgrade/util.c
index d98deb7f24..414de06349 100644
--- a/src/bin/pg_upgrade/util.c
+++ b/src/bin/pg_upgrade/util.c
@@ -38,15 +38,18 @@ report_status(eLogType type, const char *fmt,...)
}
-/* force blank output for progress display */
void
end_progress_output(void)
{
/*
- * In case nothing printed; pass a space so gcc doesn't complain about
- * empty format string.
+ * For output to a tty, erase prior contents of progress line. When either
+ * tty or verbose, indent so that report_status() output will align
+ * nicely.
*/
- prep_status(" ");
+ if (log_opts.isatty)
+ pg_log(PG_REPORT, "\r%-*s", MESSAGE_WIDTH, "");
+ else if (log_opts.verbose)
+ pg_log(PG_REPORT, "%-*s", MESSAGE_WIDTH, "");
}
@@ -75,14 +78,43 @@ prep_status(const char *fmt,...)
vsnprintf(message, sizeof(message), fmt, args);
va_end(args);
- if (strlen(message) > 0 && message[strlen(message) - 1] == '\n')
- pg_log(PG_REPORT, "%s", message);
+ /* trim strings */
+ pg_log(PG_REPORT, "%-*s", MESSAGE_WIDTH, message);
+}
+
+/*
+ * prep_status_progress
+ *
+ * Like prep_status(), but for potentially longer running operations.
+ * Details about what item is currently being processed can be displayed
+ * with pg_log(PG_STATUS, ...). A typical sequence would look like this:
+ *
+ * prep_status_progress("copying files");
+ * for (...)
+ * pg_log(PG_STATUS, "%s", filename);
+ * end_progress_output();
+ * report_status(PG_REPORT, "ok");
+ */
+void
+prep_status_progress(const char *fmt,...)
+{
+ va_list args;
+ char message[MAX_STRING];
+
+ va_start(args, fmt);
+ vsnprintf(message, sizeof(message), fmt, args);
+ va_end(args);
+
+ /*
+ * If outputting to a tty or in verbose, append newline. pg_log_v() will
+ * put the individual progress items onto the next line.
+ */
+ if (log_opts.isatty || log_opts.verbose)
+ pg_log(PG_REPORT, "%-*s\n", MESSAGE_WIDTH, message);
else
- /* trim strings that don't end in a newline */
pg_log(PG_REPORT, "%-*s", MESSAGE_WIDTH, message);
}
-
static void
pg_log_v(eLogType type, const char *fmt, va_list ap)
{
@@ -111,8 +143,15 @@ pg_log_v(eLogType type, const char *fmt, va_list ap)
break;
case PG_STATUS:
- /* for output to a display, do leading truncation and append \r */
- if (isatty(fileno(stdout)))
+ /*
+ * For output to a display, do leading truncation. Append \r so
+ * that the next message is output at the start of the line.
+ *
+ * If going to non-interactive output, only display progress if
+ * verbose is enabled. Otherwise the output gets unreasonably
+ * large by default.
+ */
+ if (log_opts.isatty)
/* -2 because we use a 2-space indent */
printf(" %s%-*.*s\r",
/* prefix with "..." if we do leading truncation */
@@ -121,7 +160,7 @@ pg_log_v(eLogType type, const char *fmt, va_list ap)
/* optional leading truncation */
strlen(message) <= MESSAGE_WIDTH - 2 ? message :
message + strlen(message) - MESSAGE_WIDTH + 3 + 2);
- else
+ else if (log_opts.verbose)
printf(" %s\n", message);
break;