Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf455fcf

Browse files
committed
Avoid unportable strftime() behavior in pg_dump/pg_dumpall.
Commitad5d46a thought that we couldget around the known portability issues of strftime's %Z specifier byusing %z instead. However, that idea seems to have been innocent ofany actual research, as it certainly missed the facts that(1) %z is not portable to pre-C99 systems, and(2) %z doesn't actually act differently from %Z on Windows anyway.Per failures on buildfarm member hamerkop.While at it, centralize the code defining what strftime format wewant to use in pg_dump; three copies of that string seems a bit much.
1 parent9711fa0 commitf455fcf

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

‎src/bin/pg_dump/dumputils.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@ typedef struct SimpleStringList
4949

5050
#defineatooid(x) ((Oid) strtoul((x), NULL, 10))
5151

52+
/*
53+
* Preferred strftime(3) format specifier for printing timestamps in pg_dump
54+
* and friends.
55+
*
56+
* We don't print the timezone on Windows, because the names are long and
57+
* localized, which means they may contain characters in various random
58+
* encodings; this has been seen to cause encoding errors when reading the
59+
* dump script. Think not to get around that by using %z, because
60+
* (1) %z is not portable to pre-C99 systems, and
61+
* (2) %z doesn't actually act differently from %Z on Windows anyway.
62+
*/
63+
#ifndefWIN32
64+
#definePGDUMP_STRFTIME_FMT "%Y-%m-%d %H:%M:%S %Z"
65+
#else
66+
#definePGDUMP_STRFTIME_FMT "%Y-%m-%d %H:%M:%S"
67+
#endif
68+
5269
externintquote_all_identifiers;
5370
externPQExpBuffer (*getLocalPQExpBuffer) (void);
5471

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,14 +1047,16 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
10471047
teSectioncurSection;
10481048
OutputContextsav;
10491049
constchar*fmtName;
1050-
structtm*tm=localtime(&AH->createDate);
10511050
charstamp_str[64];
10521051

10531052
sav=SaveOutput(AH);
10541053
if (ropt->filename)
10551054
SetOutput(AH,ropt->filename,0/* no compression */ );
10561055

1057-
strftime(stamp_str,sizeof(stamp_str),"%Y-%m-%d %H:%M:%S %z",tm);
1056+
if (strftime(stamp_str,sizeof(stamp_str),PGDUMP_STRFTIME_FMT,
1057+
localtime(&AH->createDate))==0)
1058+
strcpy(stamp_str,"[unknown]");
1059+
10581060
ahprintf(AH,";\n; Archive created at %s\n",stamp_str);
10591061
ahprintf(AH,"; dbname: %s\n; TOC Entries: %d\n; Compression: %d\n",
10601062
AH->archdbname,AH->tocCount,AH->compression);
@@ -3544,7 +3546,7 @@ dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim)
35443546
{
35453547
charbuf[64];
35463548

3547-
if (strftime(buf,sizeof(buf),"%Y-%m-%d %H:%M:%S %z",localtime(&tim))!=0)
3549+
if (strftime(buf,sizeof(buf),PGDUMP_STRFTIME_FMT,localtime(&tim))!=0)
35483550
ahprintf(AH,"-- %s %s\n\n",msg,buf);
35493551
}
35503552

‎src/bin/pg_dump/pg_dumpall.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static void makeAlterConfigCommand(PGconn *conn, const char *arrayitem,
4848
constchar*type,constchar*name,constchar*type2,
4949
constchar*name2);
5050
staticvoiddumpDatabases(PGconn*conn);
51-
staticvoiddumpTimestamp(char*msg);
51+
staticvoiddumpTimestamp(constchar*msg);
5252
staticvoiddoShellQuoting(PQExpBufferbuf,constchar*str);
5353
staticvoiddoConnStrQuoting(PQExpBufferbuf,constchar*str);
5454

@@ -2058,12 +2058,12 @@ executeCommand(PGconn *conn, const char *query)
20582058
* dumpTimestamp
20592059
*/
20602060
staticvoid
2061-
dumpTimestamp(char*msg)
2061+
dumpTimestamp(constchar*msg)
20622062
{
20632063
charbuf[64];
20642064
time_tnow=time(NULL);
20652065

2066-
if (strftime(buf,sizeof(buf),"%Y-%m-%d %H:%M:%S %z",localtime(&now))!=0)
2066+
if (strftime(buf,sizeof(buf),PGDUMP_STRFTIME_FMT,localtime(&now))!=0)
20672067
fprintf(OPF,"-- %s %s\n\n",msg,buf);
20682068
}
20692069

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp