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

Commit 9cbb5fc

Browse files
committed
Various fixes to TAR header format
Fix for endian bug in TAR output Nicer error messages in pg_dump
1 parent db2faa9 commit 9cbb5fc

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 1 addition & 1 deletion
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 19
65+
#define K_VERS_REV 20
6666

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

src/bin/pg_dump/pg_backup_tar.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,8 @@ static void _LoadBlobs(ArchiveHandle* AH, RestoreOptions *ropt)
673673
static int _WriteByte(ArchiveHandle* AH, const int i)
674674
{
675675
lclContext* ctx = (lclContext*)AH->formatData;
676-
int res;
677-
int b = i;
676+
int res;
677+
char b = i; /* Avoid endian problems */
678678

679679
res = tarWrite(&b, 1, ctx->FH);
680680
if (res != EOF) {
@@ -1088,44 +1088,50 @@ static void _tarWriteHeader(TAR_MEMBER* th)
10881088
sprintf(&h[100], "100600 ");
10891089

10901090
/* User ID 8 */
1091-
sprintf(&h[108], " 0 ");
1091+
sprintf(&h[108], " 04000 ");
10921092

10931093
/* Group 8 */
1094-
sprintf(&h[116], " 0 ");
1094+
sprintf(&h[116], " 02000 ");
10951095

10961096
/* File size 12 */
1097-
sprintf(&h[124], "%12o", th->fileLen);
1097+
sprintf(&h[124], "%10o ", th->fileLen);
10981098

10991099
/* Mod Time 12 */
1100-
sprintf(&h[136], "%12o", (int)time(NULL));
1100+
sprintf(&h[136], "%10o ", (int)time(NULL));
11011101

11021102
/* Checksum 8 */
1103-
sprintf(&h[148], "%8o", lastSum);
1103+
sprintf(&h[148], "%6o ", lastSum);
11041104

1105-
/* Link 1 */
1106-
sprintf(&h[156], "%c", LF_NORMAL);
1105+
/* Type 1 */
1106+
/* sprintf(&h[156], "%c", LF_NORMAL); */
1107+
sprintf(&h[156], "0");
11071108

11081109
/* Link name 100 (NULL) */
11091110

11101111
/* Magic 8 */
11111112
sprintf(&h[257], "ustar ");
11121113

1114+
/* GNU Version...
1115+
* sprintf(&h[257], "ustar");
1116+
* sprintf(&h[263], "00");
1117+
*/
1118+
11131119
/* User 32 */
11141120
sprintf(&h[265], "%.31s", ""); /* How do I get username reliably? Do I need to? */
11151121

11161122
/* Group 32 */
11171123
sprintf(&h[297], "%.31s", ""); /* How do I get group reliably? Do I need to? */
11181124

11191125
/* Maj Dev 8 */
1120-
/* sprintf(&h[329], "%8o", 0); */
1126+
/* sprintf(&h[329], "%6o ", 0); */
11211127

11221128
/* Min Dev */
1123-
/* sprintf(&h[337], "%8o", 0); */
1129+
/* sprintf(&h[337], "%6o ", 0); */
11241130

11251131

11261132
while ( (sum = _tarChecksum(h)) != lastSum)
11271133
{
1128-
sprintf(&h[148], "%8o", sum);
1134+
sprintf(&h[148], "%6o ", sum);
11291135
lastSum = sum;
11301136
}
11311137

src/bin/pg_dump/pg_dump.c

Lines changed: 18 additions & 2 deletions
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.175 2000/10/24 01:38:32 tgl Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.176 2000/10/24 13:24:30 pjw Exp $
2626
*
2727
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2828
*
@@ -696,7 +696,7 @@ main(int argc, char **argv)
696696
if (strcmp(progname, "pg_backup") == 0)
697697
{
698698
format = "c";
699-
outputBlobs = 1;
699+
outputBlobs = true;
700700
}
701701

702702
#ifdef HAVE_GETOPT_LONG
@@ -864,6 +864,14 @@ main(int argc, char **argv)
864864
}
865865
}
866866

867+
if (optind < (argc - 1)) {
868+
fprintf(stderr,
869+
"%s: extra parameters found on command line after '%s' (first is '%s').\n"
870+
"Please respecify command.\nUse -? for help on invocation options.\n",
871+
progname, argv[optind], argv[optind+1]);
872+
exit(1);
873+
}
874+
867875
if (dataOnly && schemaOnly)
868876
{
869877
fprintf(stderr,
@@ -888,6 +896,14 @@ main(int argc, char **argv)
888896
exit(1);
889897
}
890898

899+
if (outputBlobs == true && (format[0] == 'p' || format[0] == 'P') )
900+
{
901+
fprintf(stderr,
902+
"%s: BLOB output is not supported for plain text dump files. Use a different output format.\n",
903+
progname);
904+
exit(1);
905+
}
906+
891907
/* open the output file */
892908
switch (format[0]) {
893909

0 commit comments

Comments
 (0)