Skip to content

Commit d7e9ca7

Browse files
committed
Truncate filenames in the leadning end in pg_basebackup verbose output
When truncating at the end, like before, the output would often end up just showing the path instead of the filename. Also increase the length of the filename by 5, which still keeps us at less than 80 characters in most outputs.
1 parent f3af534 commit d7e9ca7

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ progress_report(int tablespacenum, const char *filename)
422422
totaldone / 1024);
423423
snprintf(totalsize_str, sizeof(totalsize_str), INT64_FORMAT, totalsize);
424424

425+
#define VERBOSE_FILENAME_LENGTH 35
425426
if (verbose)
426427
{
427428
if (!filename)
@@ -431,18 +432,29 @@ progress_report(int tablespacenum, const char *filename)
431432
* call)
432433
*/
433434
fprintf(stderr,
434-
ngettext("%s/%s kB (100%%), %d/%d tablespace %35s",
435-
"%s/%s kB (100%%), %d/%d tablespaces %35s",
435+
ngettext("%s/%s kB (100%%), %d/%d tablespace %*s",
436+
"%s/%s kB (100%%), %d/%d tablespaces %*s",
436437
tablespacecount),
437438
totaldone_str, totalsize_str,
438-
tablespacenum, tablespacecount, "");
439+
tablespacenum, tablespacecount,
440+
VERBOSE_FILENAME_LENGTH + 5, "");
439441
else
442+
{
443+
bool truncate = (strlen(filename) > VERBOSE_FILENAME_LENGTH);
444+
440445
fprintf(stderr,
441-
ngettext("%s/%s kB (%d%%), %d/%d tablespace (%-30.30s)",
442-
"%s/%s kB (%d%%), %d/%d tablespaces (%-30.30s)",
446+
ngettext("%s/%s kB (%d%%), %d/%d tablespace (%s%-*.*s)",
447+
"%s/%s kB (%d%%), %d/%d tablespaces (%s%-*.*s)",
443448
tablespacecount),
444449
totaldone_str, totalsize_str, percent,
445-
tablespacenum, tablespacecount, filename);
450+
tablespacenum, tablespacecount,
451+
/* Prefix with "..." if we do leading truncation */
452+
truncate ? "..." : "",
453+
truncate ? VERBOSE_FILENAME_LENGTH - 3 : VERBOSE_FILENAME_LENGTH,
454+
truncate ? VERBOSE_FILENAME_LENGTH - 3 : VERBOSE_FILENAME_LENGTH,
455+
/* Truncate filename at beginning if it's too long */
456+
truncate ? filename + strlen(filename) - VERBOSE_FILENAME_LENGTH + 3 : filename);
457+
}
446458
}
447459
else
448460
fprintf(stderr,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy