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

Commit 4a19bd8

Browse files
committed
- Fix help output: replace 'f' with 't' and change desc
- Add extra arg to formatStringLiteral to specify how to handle LF & TAB. I opted for encoding them except in procedure bodies & comments - Fixed bug in tar file input when restoring blobs
1 parent f7a839b commit 4a19bd8

File tree

3 files changed

+82
-38
lines changed

3 files changed

+82
-38
lines changed

src/bin/pg_dump/pg_backup_archiver.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ typedef z_stream *z_streamp;
6262

6363
#define K_VERS_MAJOR 1
6464
#define K_VERS_MINOR 4
65-
#define K_VERS_REV 27
65+
#define K_VERS_REV 28
6666

6767
/* Data block types */
6868
#define BLK_DATA 1

src/bin/pg_dump/pg_backup_tar.c

+39-12
Original file line numberDiff line numberDiff line change
@@ -1061,26 +1061,53 @@ static int _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER* th)
10611061
int sum, chk;
10621062
int len;
10631063
int hPos;
1064+
int i;
1065+
bool gotBlock = false;
10641066

1065-
/*
1066-
* if ( ftell(ctx->tarFH) != ctx->tarFHpos)
1067-
* die_horribly(AH, "%s: mismatch in actual vs. predicted file pos - %d vs. %d\n",
1068-
* progname, ftell(ctx->tarFH), ctx->tarFHpos);
1069-
*/
1067+
while (!gotBlock)
1068+
{
1069+
/*
1070+
* if ( ftell(ctx->tarFH) != ctx->tarFHpos)
1071+
* die_horribly(AH, "%s: mismatch in actual vs. predicted file pos - %d vs. %d\n",
1072+
* progname, ftell(ctx->tarFH), ctx->tarFHpos);
1073+
*/
10701074

1071-
hPos = ctx->tarFHpos;
1075+
/* Save the pos for reporting purposes */
1076+
hPos = ctx->tarFHpos;
10721077

1073-
len = _tarReadRaw(AH, &h[0], 512, NULL, ctx->tarFH);
1074-
if (len == 0) /* EOF */
1075-
return 0;
1078+
/* Read a 512 byte block, return EOF, exit if short */
1079+
len = _tarReadRaw(AH, &h[0], 512, NULL, ctx->tarFH);
1080+
if (len == 0) /* EOF */
1081+
return 0;
1082+
1083+
if (len != 512)
1084+
die_horribly(AH, "%s: incomplete tar header found (%d bytes)\n", progname, len);
1085+
1086+
/* Calc checksum */
1087+
chk = _tarChecksum(&h[0]);
10761088

1077-
if (len != 512)
1078-
die_horribly(AH, "%s: incomplete tar header found (%d bytes)\n", progname, len);
1089+
/*
1090+
* If the checksum failed, see if it is a null block.
1091+
* If so, then just try with next block...
1092+
*/
1093+
1094+
if (chk == sum) {
1095+
gotBlock = true;
1096+
} else {
1097+
for( i = 0 ; i < 512 ; i++)
1098+
{
1099+
if (h[0] != 0)
1100+
{
1101+
gotBlock = true;
1102+
break;
1103+
}
1104+
}
1105+
}
1106+
}
10791107

10801108
sscanf(&h[0], "%99s", &name[0]);
10811109
sscanf(&h[124], "%12o", &len);
10821110
sscanf(&h[148], "%8o", &sum);
1083-
chk = _tarChecksum(&h[0]);
10841111

10851112
ahlog(AH, 3, "TOC Entry %s at %d (len=%d, chk=%d)\n", &name[0], hPos, len, sum);
10861113

src/bin/pg_dump/pg_dump.c

+42-25
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.191 2001/02/10 02:31:27 tgl Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.192 2001/02/13 01:31:54 pjw Exp $
2626
*
2727
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2828
*
@@ -96,11 +96,17 @@
9696
* table with the currently implementation, and (b) it's not clear how to restore
9797
* a partial BLOB backup (given the current OID-based BLOB implementation).
9898
*
99-
* Modifications - 04-Jan-2000 - pjw@rhyme.com.au
99+
* Modifications - 04-Jan-2001 - pjw@rhyme.com.au
100100
*
101101
* - Check ntuples == 1 for various SELECT statements.
102102
* - Fix handling of --tables=* (multiple tables never worked properly, AFAICT)
103103
*
104+
* Modifications - 13-Feb-2001 - pjw@rhyme.com.au
105+
*
106+
* - Fix help output: replace 'f' with 't' and change desc.
107+
* - Add extra arg to formatStringLiteral to specify how to handle LF & TAB.
108+
* I opted for encoding them except in procedure bodies.
109+
*
104110
*-------------------------------------------------------------------------
105111
*/
106112

@@ -140,14 +146,23 @@
140146

141147
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
142148

149+
150+
typedef enum _formatLiteralOptions {
151+
CONV_ALL = 0,
152+
PASS_LFTAB = 3 /* NOTE: 1 and 2 are reserved in case we want to make a mask. */
153+
/* We could make this a bit mask for control chars, but I don't */
154+
/* see any value in making it more complex...the current code */
155+
/* only checks for 'opts == CONV_ALL' anyway. */
156+
} formatLiteralOptions;
157+
143158
static void dumpComment(Archive *outfile, const char *target, const char *oid);
144159
static void dumpSequence(Archive *fout, TableInfo tbinfo);
145160
static void dumpACL(Archive *fout, TableInfo tbinfo);
146161
static void dumpTriggers(Archive *fout, const char *tablename,
147162
TableInfo *tblinfo, int numTables);
148163
static void dumpRules(Archive *fout, const char *tablename,
149164
TableInfo *tblinfo, int numTables);
150-
static void formatStringLiteral(PQExpBuffer buf, const char *str);
165+
static void formatStringLiteral(PQExpBuffer buf, const char *str, const formatLiteralOptions opts);
151166
static void clearTableInfo(TableInfo *, int);
152167
static void dumpOneFunc(Archive *fout, FuncInfo *finfo, int i,
153168
TypeInfo *tinfo, int numTypes);
@@ -209,7 +224,7 @@ help(const char *progname)
209224
" -d, --inserts dump data as INSERT, rather than COPY, commands\n"
210225
" -D, --attribute-inserts dump data as INSERT commands with attribute names\n"
211226
" -f, --file=FILENAME specify output file name\n"
212-
" -F, --format {c|f|p} output file format (custom, files, plain text)\n"
227+
" -F, --format {c|t|p} output file format (custom, tar, plain text)\n"
213228
" -h, --host=HOSTNAME server host name\n"
214229
" -i, --ignore-version proceed when database version != pg_dump version\n"
215230
" -n, --no-quotes suppress most quotes around identifiers\n"
@@ -238,7 +253,7 @@ help(const char *progname)
238253
" -d dump data as INSERT, rather than COPY, commands\n"
239254
" -D dump data as INSERT commands with attribute names\n"
240255
" -f FILENAME specify output file name\n"
241-
" -F {c|f|p} output file format (custom, files, plain text)\n"
256+
" -F {c|t|p} output file format (custom, tar, plain text)\n"
242257
" -h HOSTNAME server host name\n"
243258
" -i proceed when database version != pg_dump version\n"
244259
" -n suppress most quotes around identifiers\n"
@@ -509,7 +524,7 @@ dumpClasses_dumpData(Archive *fout, char* oid, void *dctxv)
509524
* with appropriate escaping of special characters.
510525
*/
511526
resetPQExpBuffer(q);
512-
formatStringLiteral(q, PQgetvalue(res, tuple, field));
527+
formatStringLiteral(q, PQgetvalue(res, tuple, field), CONV_ALL);
513528
archprintf(fout, "%s", q->data);
514529
break;
515530
}
@@ -528,7 +543,7 @@ dumpClasses_dumpData(Archive *fout, char* oid, void *dctxv)
528543
* The literal is appended to the given PQExpBuffer.
529544
*/
530545
static void
531-
formatStringLiteral(PQExpBuffer buf, const char *str)
546+
formatStringLiteral(PQExpBuffer buf, const char *str, const formatLiteralOptions opts)
532547
{
533548
appendPQExpBufferChar(buf, '\'');
534549
while (*str)
@@ -541,7 +556,9 @@ formatStringLiteral(PQExpBuffer buf, const char *str)
541556
appendPQExpBufferChar(buf, ch);
542557
}
543558
else if ((unsigned char) ch < (unsigned char) ' ' &&
544-
ch != '\n' && ch != '\t')
559+
( opts == CONV_ALL
560+
|| (ch != '\n' && ch != '\t')
561+
))
545562
{
546563
/* generate octal escape for control chars other than whitespace */
547564
appendPQExpBufferChar(buf, '\\');
@@ -1099,7 +1116,7 @@ dumpDatabase(Archive *AH)
10991116
/* Get the dba */
11001117
appendPQExpBuffer(dbQry, "select (select usename from pg_user where datdba = usesysid) as dba from pg_database"
11011118
" where datname = ");
1102-
formatStringLiteral(dbQry, PQdb(g_conn));
1119+
formatStringLiteral(dbQry, PQdb(g_conn), CONV_ALL);
11031120

11041121
res = PQexec(g_conn, dbQry->data);
11051122
if (!res ||
@@ -1988,7 +2005,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
19882005

19892006
resetPQExpBuffer(query);
19902007
appendPQExpBuffer(query, "SELECT pg_get_viewdef(");
1991-
formatStringLiteral(query, tblinfo[i].relname);
2008+
formatStringLiteral(query, tblinfo[i].relname, CONV_ALL);
19922009
appendPQExpBuffer(query, ") as viewdef");
19932010
res2 = PQexec(g_conn, query->data);
19942011
if (!res2 || PQresultStatus(res2) != PGRES_TUPLES_OK)
@@ -2823,7 +2840,7 @@ dumpComment(Archive *fout, const char *target, const char *oid)
28232840
i_description = PQfnumber(res, "description");
28242841
resetPQExpBuffer(query);
28252842
appendPQExpBuffer(query, "COMMENT ON %s IS ", target);
2826-
formatStringLiteral(query, PQgetvalue(res, 0, i_description));
2843+
formatStringLiteral(query, PQgetvalue(res, 0, i_description), PASS_LFTAB);
28272844
appendPQExpBuffer(query, ";\n");
28282845

28292846
ArchiveEntry(fout, oid, target, "COMMENT", NULL, query->data, "" /*Del*/,
@@ -2859,7 +2876,7 @@ dumpDBComment(Archive *fout)
28592876

28602877
query = createPQExpBuffer();
28612878
appendPQExpBuffer(query, "SELECT oid FROM pg_database WHERE datname = ");
2862-
formatStringLiteral(query, PQdb(g_conn));
2879+
formatStringLiteral(query, PQdb(g_conn), CONV_ALL);
28632880

28642881
/*** Execute query ***/
28652882

@@ -2947,7 +2964,7 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
29472964
fmtId(tinfo[i].typsend, force_quotes));
29482965
appendPQExpBuffer(q, " receive = %s, default = ",
29492966
fmtId(tinfo[i].typreceive, force_quotes));
2950-
formatStringLiteral(q, tinfo[i].typdefault);
2967+
formatStringLiteral(q, tinfo[i].typdefault, CONV_ALL);
29512968

29522969
if (tinfo[i].isArray)
29532970
{
@@ -2964,7 +2981,7 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
29642981
}
29652982

29662983
appendPQExpBuffer(q, ", element = %s, delimiter = ", elemType);
2967-
formatStringLiteral(q, tinfo[i].typdelim);
2984+
formatStringLiteral(q, tinfo[i].typdelim, CONV_ALL);
29682985
}
29692986
if (tinfo[i].passedbyvalue)
29702987
appendPQExpBuffer(q, ",passedbyvalue);\n");
@@ -3057,16 +3074,16 @@ dumpProcLangs(Archive *fout, FuncInfo *finfo, int numFuncs,
30573074
lancompiler = PQgetvalue(res, i, i_lancompiler);
30583075

30593076
appendPQExpBuffer(delqry, "DROP PROCEDURAL LANGUAGE ");
3060-
formatStringLiteral(delqry, lanname);
3077+
formatStringLiteral(delqry, lanname, CONV_ALL);
30613078
appendPQExpBuffer(delqry, ";\n");
30623079

30633080
appendPQExpBuffer(defqry, "CREATE %sPROCEDURAL LANGUAGE ",
30643081
(PQgetvalue(res, i, i_lanpltrusted)[0] == 't') ?
30653082
"TRUSTED " : "");
3066-
formatStringLiteral(defqry, lanname);
3083+
formatStringLiteral(defqry, lanname, CONV_ALL);
30673084
appendPQExpBuffer(defqry, " HANDLER %s LANCOMPILER ",
30683085
fmtId(finfo[fidx].proname, force_quotes));
3069-
formatStringLiteral(defqry, lancompiler);
3086+
formatStringLiteral(defqry, lancompiler, CONV_ALL);
30703087
appendPQExpBuffer(defqry, ";\n");
30713088

30723089
ArchiveEntry(fout, PQgetvalue(res, i, i_oid), lanname, "PROCEDURAL LANGUAGE",
@@ -3156,19 +3173,19 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i,
31563173
if (strcmp(finfo[i].probin, "-") != 0)
31573174
{
31583175
appendPQExpBuffer(asPart, "AS ");
3159-
formatStringLiteral(asPart, finfo[i].probin);
3176+
formatStringLiteral(asPart, finfo[i].probin, CONV_ALL);
31603177
if (strcmp(finfo[i].prosrc, "-") != 0)
31613178
{
31623179
appendPQExpBuffer(asPart, ", ");
3163-
formatStringLiteral(asPart, finfo[i].prosrc);
3180+
formatStringLiteral(asPart, finfo[i].prosrc, PASS_LFTAB);
31643181
}
31653182
}
31663183
else
31673184
{
31683185
if (strcmp(finfo[i].prosrc, "-") != 0)
31693186
{
31703187
appendPQExpBuffer(asPart, "AS ");
3171-
formatStringLiteral(asPart, finfo[i].prosrc);
3188+
formatStringLiteral(asPart, finfo[i].prosrc, PASS_LFTAB);
31723189
}
31733190
}
31743191

@@ -3233,7 +3250,7 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo, int i,
32333250
(finfo[i].retset) ? "SETOF " : "",
32343251
rettypename,
32353252
asPart->data);
3236-
formatStringLiteral(q, func_lang);
3253+
formatStringLiteral(q, func_lang, CONV_ALL);
32373254

32383255
if (finfo[i].iscachable || finfo[i].isstrict) /* OR in new attrs here */
32393256
{
@@ -3477,7 +3494,7 @@ dumpAggs(Archive *fout, AggInfo *agginfo, int numAggs,
34773494
if (agginfo[i].agginitval)
34783495
{
34793496
appendPQExpBuffer(details, ", INITCOND = ");
3480-
formatStringLiteral(details, agginfo[i].agginitval);
3497+
formatStringLiteral(details, agginfo[i].agginitval, CONV_ALL);
34813498
}
34823499

34833500
if (!(strcmp(agginfo[i].aggfinalfn, "-") == 0))
@@ -4267,7 +4284,7 @@ findLastBuiltinOid(const char* dbname)
42674284

42684285
resetPQExpBuffer(query);
42694286
appendPQExpBuffer(query, "SELECT datlastsysoid from pg_database where datname = ");
4270-
formatStringLiteral(query, dbname);
4287+
formatStringLiteral(query, dbname, CONV_ALL);
42714288

42724289
res = PQexec(g_conn, query->data);
42734290
if (res == NULL ||
@@ -4376,7 +4393,7 @@ dumpSequence(Archive *fout, TableInfo tbinfo)
43764393

43774394
resetPQExpBuffer(query);
43784395
appendPQExpBuffer(query, "SELECT setval (");
4379-
formatStringLiteral(query, fmtId(tbinfo.relname, force_quotes));
4396+
formatStringLiteral(query, fmtId(tbinfo.relname, force_quotes), CONV_ALL);
43804397
appendPQExpBuffer(query, ", %d, '%c');\n", last, called);
43814398

43824399
ArchiveEntry(fout, tbinfo.oid, fmtId(tbinfo.relname, force_quotes), "SEQUENCE SET", NULL,
@@ -4458,7 +4475,7 @@ dumpRules(Archive *fout, const char *tablename,
44584475
" pg_rewrite.oid, pg_rewrite.rulename "
44594476
"FROM pg_rewrite, pg_class, pg_rules "
44604477
"WHERE pg_class.relname = ");
4461-
formatStringLiteral(query, tblinfo[t].relname);
4478+
formatStringLiteral(query, tblinfo[t].relname, CONV_ALL);
44624479
appendPQExpBuffer(query,
44634480
" AND pg_rewrite.ev_class = pg_class.oid "
44644481
" AND pg_rules.tablename = pg_class.relname "

0 commit comments

Comments
 (0)