Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5fc2d7e

Browse files
committed
Suppress timezone (%Z) part of timestamp display when running on Windows,
because on that platform strftime produces localized zone names in varying encodings. Even though it's only in a comment, this can cause encoding errors when reloading the dump script. Per suggestion from Andreas Seltenreich. Also, suppress %Z on Windows in the %s escape of log_line_prefix ... not sure why this one is different from the other two, but it shouldn't be.
1 parent c714e5c commit 5fc2d7e

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

src/backend/utils/error/elog.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*
4343
*
4444
* IDENTIFICATION
45-
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.176 2006/11/21 00:49:55 tgl Exp $
45+
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.177 2006/11/21 22:19:46 tgl Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -1471,7 +1471,7 @@ log_line_prefix(StringInfo buf)
14711471
char strfbuf[128];
14721472

14731473
strftime(strfbuf, sizeof(strfbuf),
1474-
/* Win32 timezone names are too long so don't print them. */
1474+
/* Win32 timezone names are too long so don't print them */
14751475
#ifndef WIN32
14761476
"%Y-%m-%d %H:%M:%S %Z",
14771477
#else
@@ -1487,7 +1487,12 @@ log_line_prefix(StringInfo buf)
14871487
char strfbuf[128];
14881488

14891489
strftime(strfbuf, sizeof(strfbuf),
1490+
/* Win32 timezone names are too long so don't print them */
1491+
#ifndef WIN32
14901492
"%Y-%m-%d %H:%M:%S %Z",
1493+
#else
1494+
"%Y-%m-%d %H:%M:%S",
1495+
#endif
14911496
localtime(&MyProcPort->session_start));
14921497
appendStringInfoString(buf, strfbuf);
14931498
}

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.137 2006/10/14 23:07:22 tgl Exp $
18+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.138 2006/11/21 22:19:46 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -2780,6 +2780,18 @@ dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim)
27802780
{
27812781
char buf[256];
27822782

2783-
if (strftime(buf, 256, "%Y-%m-%d %H:%M:%S %Z", localtime(&tim)) != 0)
2783+
/*
2784+
* We don't print the timezone on Win32, because the names are long and
2785+
* localized, which means they may contain characters in various random
2786+
* encodings; this has been seen to cause encoding errors when reading
2787+
* the dump script.
2788+
*/
2789+
if (strftime(buf, sizeof(buf),
2790+
#ifndef WIN32
2791+
"%Y-%m-%d %H:%M:%S %Z",
2792+
#else
2793+
"%Y-%m-%d %H:%M:%S",
2794+
#endif
2795+
localtime(&tim)) != 0)
27842796
ahprintf(AH, "-- %s %s\n\n", msg, buf);
27852797
}

src/bin/pg_dump/pg_dumpall.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
88
*
9-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.84 2006/10/07 20:59:05 petere Exp $
9+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.85 2006/11/21 22:19:46 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -1320,6 +1320,18 @@ dumpTimestamp(char *msg)
13201320
char buf[256];
13211321
time_t now = time(NULL);
13221322

1323-
if (strftime(buf, 256, "%Y-%m-%d %H:%M:%S %Z", localtime(&now)) != 0)
1323+
/*
1324+
* We don't print the timezone on Win32, because the names are long and
1325+
* localized, which means they may contain characters in various random
1326+
* encodings; this has been seen to cause encoding errors when reading
1327+
* the dump script.
1328+
*/
1329+
if (strftime(buf, sizeof(buf),
1330+
#ifndef WIN32
1331+
"%Y-%m-%d %H:%M:%S %Z",
1332+
#else
1333+
"%Y-%m-%d %H:%M:%S",
1334+
#endif
1335+
localtime(&now)) != 0)
13241336
printf("-- %s %s\n\n", msg, buf);
13251337
}

0 commit comments

Comments
 (0)