15
15
*
16
16
*
17
17
* IDENTIFICATION
18
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.78 2003/10/03 20:10:59 tgl Exp $
18
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.79 2003/10/20 21:05:11 tgl Exp $
19
19
*
20
20
*-------------------------------------------------------------------------
21
21
*/
@@ -381,7 +381,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
381
381
/*
382
382
* Clean up & we're done.
383
383
*/
384
- if (ropt -> filename )
384
+ if (ropt -> filename || ropt -> compression )
385
385
ResetOutput (AH , sav );
386
386
387
387
if (ropt -> useDB )
@@ -596,7 +596,7 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
596
596
char * fmtName ;
597
597
598
598
if (ropt -> filename )
599
- sav = SetOutput (AH , ropt -> filename , ropt -> compression );
599
+ sav = SetOutput (AH , ropt -> filename , 0 /* no compression */ );
600
600
601
601
ahprintf (AH , ";\n; Archive created at %s" , ctime (& AH -> createDate ));
602
602
ahprintf (AH , "; dbname: %s\n; TOC Entries: %d\n; Compression: %d\n" ,
@@ -1039,23 +1039,19 @@ OutputContext
1039
1039
SetOutput (ArchiveHandle * AH , char * filename , int compression )
1040
1040
{
1041
1041
OutputContext sav ;
1042
-
1043
- #ifdef HAVE_LIBZ
1044
- char fmode [10 ];
1045
- #endif
1046
- int fn = 0 ;
1042
+ int fn ;
1047
1043
1048
1044
/* Replace the AH output file handle */
1049
1045
sav .OF = AH -> OF ;
1050
1046
sav .gzOut = AH -> gzOut ;
1051
1047
1052
1048
if (filename )
1053
- fn = 0 ;
1049
+ fn = -1 ;
1054
1050
else if (AH -> FH )
1055
1051
fn = fileno (AH -> FH );
1056
1052
else if (AH -> fSpec )
1057
1053
{
1058
- fn = 0 ;
1054
+ fn = -1 ;
1059
1055
filename = AH -> fSpec ;
1060
1056
}
1061
1057
else
@@ -1065,27 +1061,25 @@ SetOutput(ArchiveHandle *AH, char *filename, int compression)
1065
1061
#ifdef HAVE_LIBZ
1066
1062
if (compression != 0 )
1067
1063
{
1064
+ char fmode [10 ];
1065
+
1066
+ /* Don't use PG_BINARY_x since this is zlib */
1068
1067
sprintf (fmode , "wb%d" , compression );
1069
- if (fn )
1070
- {
1071
- AH -> OF = gzdopen (dup (fn ), fmode ); /* Don't use PG_BINARY_x
1072
- * since this is zlib */
1073
- }
1068
+ if (fn >= 0 )
1069
+ AH -> OF = gzdopen (dup (fn ), fmode );
1074
1070
else
1075
1071
AH -> OF = gzopen (filename , fmode );
1076
1072
AH -> gzOut = 1 ;
1077
1073
}
1078
1074
else
1079
- { /* Use fopen */
1080
1075
#endif
1081
- if (fn )
1076
+ { /* Use fopen */
1077
+ if (fn >= 0 )
1082
1078
AH -> OF = fdopen (dup (fn ), PG_BINARY_W );
1083
1079
else
1084
1080
AH -> OF = fopen (filename , PG_BINARY_W );
1085
1081
AH -> gzOut = 0 ;
1086
- #ifdef HAVE_LIBZ
1087
1082
}
1088
- #endif
1089
1083
1090
1084
if (!AH -> OF )
1091
1085
die_horribly (AH , modulename , "could not open output file: %s\n" , strerror (errno ));
@@ -1104,7 +1098,8 @@ ResetOutput(ArchiveHandle *AH, OutputContext sav)
1104
1098
res = fclose (AH -> OF );
1105
1099
1106
1100
if (res != 0 )
1107
- die_horribly (AH , modulename , "could not close output file: %s\n" , strerror (errno ));
1101
+ die_horribly (AH , modulename , "could not close output file: %s\n" ,
1102
+ strerror (errno ));
1108
1103
1109
1104
AH -> gzOut = sav .gzOut ;
1110
1105
AH -> OF = sav .OF ;
0 commit comments