@@ -75,6 +75,13 @@ typedef struct _parallel_slot
75
75
76
76
#define NO_SLOT (-1)
77
77
78
+ /* state needed to save/restore an archive's output target */
79
+ typedef struct _outputContext
80
+ {
81
+ void * OF ;
82
+ int gzOut ;
83
+ } OutputContext ;
84
+
78
85
const char * progname ;
79
86
80
87
static const char * modulename = gettext_noop ("archiver" );
@@ -114,8 +121,9 @@ static void _write_msg(const char *modulename, const char *fmt, va_list ap);
114
121
static void _die_horribly (ArchiveHandle * AH , const char * modulename , const char * fmt , va_list ap );
115
122
116
123
static void dumpTimestamp (ArchiveHandle * AH , const char * msg , time_t tim );
117
- static OutputContext SetOutput (ArchiveHandle * AH , char * filename , int compression );
118
- static void ResetOutput (ArchiveHandle * AH , OutputContext savedContext );
124
+ static void SetOutput (ArchiveHandle * AH , char * filename , int compression );
125
+ static OutputContext SaveOutput (ArchiveHandle * AH );
126
+ static void RestoreOutput (ArchiveHandle * AH , OutputContext savedContext );
119
127
120
128
static int restore_toc_entry (ArchiveHandle * AH , TocEntry * te ,
121
129
RestoreOptions * ropt , bool is_parallel );
@@ -299,8 +307,9 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
299
307
/*
300
308
* Setup the output file if necessary.
301
309
*/
310
+ sav = SaveOutput (AH );
302
311
if (ropt -> filename || ropt -> compression )
303
- sav = SetOutput (AH , ropt -> filename , ropt -> compression );
312
+ SetOutput (AH , ropt -> filename , ropt -> compression );
304
313
305
314
ahprintf (AH , "--\n-- PostgreSQL database dump\n--\n\n" );
306
315
@@ -420,7 +429,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
420
429
AH -> stage = STAGE_FINALIZING ;
421
430
422
431
if (ropt -> filename || ropt -> compression )
423
- ResetOutput (AH , sav );
432
+ RestoreOutput (AH , sav );
424
433
425
434
if (ropt -> useDB )
426
435
{
@@ -782,8 +791,9 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
782
791
OutputContext sav ;
783
792
char * fmtName ;
784
793
794
+ sav = SaveOutput (AH );
785
795
if (ropt -> filename )
786
- sav = SetOutput (AH , ropt -> filename , 0 /* no compression */ );
796
+ SetOutput (AH , ropt -> filename , 0 /* no compression */ );
787
797
788
798
ahprintf (AH , ";\n; Archive created at %s" , ctime (& AH -> createDate ));
789
799
ahprintf (AH , "; dbname: %s\n; TOC Entries: %d\n; Compression: %d\n" ,
@@ -839,7 +849,7 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
839
849
}
840
850
841
851
if (ropt -> filename )
842
- ResetOutput (AH , sav );
852
+ RestoreOutput (AH , sav );
843
853
}
844
854
845
855
/***********
@@ -1117,16 +1127,11 @@ archprintf(Archive *AH, const char *fmt,...)
1117
1127
* Stuff below here should be 'private' to the archiver routines
1118
1128
*******************************/
1119
1129
1120
- static OutputContext
1130
+ static void
1121
1131
SetOutput (ArchiveHandle * AH , char * filename , int compression )
1122
1132
{
1123
- OutputContext sav ;
1124
1133
int fn ;
1125
1134
1126
- /* Replace the AH output file handle */
1127
- sav .OF = AH -> OF ;
1128
- sav .gzOut = AH -> gzOut ;
1129
-
1130
1135
if (filename )
1131
1136
fn = -1 ;
1132
1137
else if (AH -> FH )
@@ -1182,12 +1187,21 @@ SetOutput(ArchiveHandle *AH, char *filename, int compression)
1182
1187
die_horribly (AH , modulename , "could not open output file: %s\n" ,
1183
1188
strerror (errno ));
1184
1189
}
1190
+ }
1191
+
1192
+ static OutputContext
1193
+ SaveOutput (ArchiveHandle * AH )
1194
+ {
1195
+ OutputContext sav ;
1196
+
1197
+ sav .OF = AH -> OF ;
1198
+ sav .gzOut = AH -> gzOut ;
1185
1199
1186
1200
return sav ;
1187
1201
}
1188
1202
1189
1203
static void
1190
- ResetOutput (ArchiveHandle * AH , OutputContext sav )
1204
+ RestoreOutput (ArchiveHandle * AH , OutputContext savedContext )
1191
1205
{
1192
1206
int res ;
1193
1207
@@ -1200,8 +1214,8 @@ ResetOutput(ArchiveHandle *AH, OutputContext sav)
1200
1214
die_horribly (AH , modulename , "could not close output file: %s\n" ,
1201
1215
strerror (errno ));
1202
1216
1203
- AH -> gzOut = sav .gzOut ;
1204
- AH -> OF = sav .OF ;
1217
+ AH -> gzOut = savedContext .gzOut ;
1218
+ AH -> OF = savedContext .OF ;
1205
1219
}
1206
1220
1207
1221
0 commit comments