@@ -75,6 +75,13 @@ typedef struct _parallel_slot
7575
7676#define NO_SLOT (-1)
7777
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+
7885const char * progname ;
7986
8087static const char * modulename = gettext_noop ("archiver" );
@@ -114,8 +121,9 @@ static void _write_msg(const char *modulename, const char *fmt, va_list ap);
114121static void _die_horribly (ArchiveHandle * AH ,const char * modulename ,const char * fmt ,va_list ap );
115122
116123static 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 );
119127
120128static int restore_toc_entry (ArchiveHandle * AH ,TocEntry * te ,
121129RestoreOptions * ropt ,bool is_parallel );
@@ -299,8 +307,9 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
299307/*
300308 * Setup the output file if necessary.
301309 */
310+ sav = SaveOutput (AH );
302311if (ropt -> filename || ropt -> compression )
303- sav = SetOutput (AH ,ropt -> filename ,ropt -> compression );
312+ SetOutput (AH ,ropt -> filename ,ropt -> compression );
304313
305314ahprintf (AH ,"--\n-- PostgreSQL database dump\n--\n\n" );
306315
@@ -420,7 +429,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
420429AH -> stage = STAGE_FINALIZING ;
421430
422431if (ropt -> filename || ropt -> compression )
423- ResetOutput (AH ,sav );
432+ RestoreOutput (AH ,sav );
424433
425434if (ropt -> useDB )
426435{
@@ -782,8 +791,9 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
782791OutputContext sav ;
783792char * fmtName ;
784793
794+ sav = SaveOutput (AH );
785795if (ropt -> filename )
786- sav = SetOutput (AH ,ropt -> filename ,0 /* no compression */ );
796+ SetOutput (AH ,ropt -> filename ,0 /* no compression */ );
787797
788798ahprintf (AH ,";\n; Archive created at %s" ,ctime (& AH -> createDate ));
789799ahprintf (AH ,"; dbname: %s\n; TOC Entries: %d\n; Compression: %d\n" ,
@@ -839,7 +849,7 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
839849}
840850
841851if (ropt -> filename )
842- ResetOutput (AH ,sav );
852+ RestoreOutput (AH ,sav );
843853}
844854
845855/***********
@@ -1117,16 +1127,11 @@ archprintf(Archive *AH, const char *fmt,...)
11171127 * Stuff below here should be 'private' to the archiver routines
11181128 *******************************/
11191129
1120- static OutputContext
1130+ static void
11211131SetOutput (ArchiveHandle * AH ,char * filename ,int compression )
11221132{
1123- OutputContext sav ;
11241133int fn ;
11251134
1126- /* Replace the AH output file handle */
1127- sav .OF = AH -> OF ;
1128- sav .gzOut = AH -> gzOut ;
1129-
11301135if (filename )
11311136fn = -1 ;
11321137else if (AH -> FH )
@@ -1182,12 +1187,21 @@ SetOutput(ArchiveHandle *AH, char *filename, int compression)
11821187die_horribly (AH ,modulename ,"could not open output file: %s\n" ,
11831188strerror (errno ));
11841189}
1190+ }
1191+
1192+ static OutputContext
1193+ SaveOutput (ArchiveHandle * AH )
1194+ {
1195+ OutputContext sav ;
1196+
1197+ sav .OF = AH -> OF ;
1198+ sav .gzOut = AH -> gzOut ;
11851199
11861200return sav ;
11871201}
11881202
11891203static void
1190- ResetOutput (ArchiveHandle * AH ,OutputContext sav )
1204+ RestoreOutput (ArchiveHandle * AH ,OutputContext savedContext )
11911205{
11921206int res ;
11931207
@@ -1200,8 +1214,8 @@ ResetOutput(ArchiveHandle *AH, OutputContext sav)
12001214die_horribly (AH ,modulename ,"could not close output file: %s\n" ,
12011215strerror (errno ));
12021216
1203- AH -> gzOut = sav .gzOut ;
1204- AH -> OF = sav .OF ;
1217+ AH -> gzOut = savedContext .gzOut ;
1218+ AH -> OF = savedContext .OF ;
12051219}
12061220
12071221