#define NO_SLOT (-1)
+/* state needed to save/restore an archive's output target */
+typedef struct _outputContext
+{
+ void *OF;
+ int gzOut;
+} OutputContext;
+
const char *progname;
static const char *modulename = gettext_noop("archiver");
static void _die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_list ap);
static void dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim);
-static OutputContext SetOutput(ArchiveHandle *AH, char *filename, int compression);
-static void ResetOutput(ArchiveHandle *AH, OutputContext savedContext);
+static void SetOutput(ArchiveHandle *AH, char *filename, int compression);
+static OutputContext SaveOutput(ArchiveHandle *AH);
+static void RestoreOutput(ArchiveHandle *AH, OutputContext savedContext);
static int restore_toc_entry(ArchiveHandle *AH, TocEntry *te,
RestoreOptions *ropt, bool is_parallel);
/*
* Setup the output file if necessary.
*/
+ sav = SaveOutput(AH);
if (ropt->filename || ropt->compression)
- sav = SetOutput(AH, ropt->filename, ropt->compression);
+ SetOutput(AH, ropt->filename, ropt->compression);
ahprintf(AH, "--\n-- PostgreSQL database dump\n--\n\n");
AH->stage = STAGE_FINALIZING;
if (ropt->filename || ropt->compression)
- ResetOutput(AH, sav);
+ RestoreOutput(AH, sav);
if (ropt->useDB)
{
OutputContext sav;
char *fmtName;
+ sav = SaveOutput(AH);
if (ropt->filename)
- sav = SetOutput(AH, ropt->filename, 0 /* no compression */ );
+ SetOutput(AH, ropt->filename, 0 /* no compression */ );
ahprintf(AH, ";\n; Archive created at %s", ctime(&AH->createDate));
ahprintf(AH, "; dbname: %s\n; TOC Entries: %d\n; Compression: %d\n",
}
if (ropt->filename)
- ResetOutput(AH, sav);
+ RestoreOutput(AH, sav);
}
/***********
* Stuff below here should be 'private' to the archiver routines
*******************************/
-static OutputContext
+static void
SetOutput(ArchiveHandle *AH, char *filename, int compression)
{
- OutputContext sav;
int fn;
- /* Replace the AH output file handle */
- sav.OF = AH->OF;
- sav.gzOut = AH->gzOut;
-
if (filename)
fn = -1;
else if (AH->FH)
die_horribly(AH, modulename, "could not open output file: %s\n",
strerror(errno));
}
+}
+
+static OutputContext
+SaveOutput(ArchiveHandle *AH)
+{
+ OutputContext sav;
+
+ sav.OF = AH->OF;
+ sav.gzOut = AH->gzOut;
return sav;
}
static void
-ResetOutput(ArchiveHandle *AH, OutputContext sav)
+RestoreOutput(ArchiveHandle *AH, OutputContext savedContext)
{
int res;
die_horribly(AH, modulename, "could not close output file: %s\n",
strerror(errno));
- AH->gzOut = sav.gzOut;
- AH->OF = sav.OF;
+ AH->gzOut = savedContext.gzOut;
+ AH->OF = savedContext.OF;
}