Commit fd5437c7 authored by Tom Lane's avatar Tom Lane

Fix breakage created by addition of separate 'acl pass' in pg_dump.

Also clean up incredibly poor style in TocIDRequired() usage.
parent 5ca9687f
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.102 2005/01/23 00:03:54 tgl Exp $ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.103 2005/01/25 22:44:31 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -27,21 +27,14 @@ ...@@ -27,21 +27,14 @@
#include "dumputils.h" #include "dumputils.h"
#include <ctype.h> #include <ctype.h>
#include <errno.h>
#include <unistd.h> #include <unistd.h>
#include "pqexpbuffer.h" #include "pqexpbuffer.h"
#include "libpq/libpq-fs.h" #include "libpq/libpq-fs.h"
typedef enum _teReqs_
{
REQ_SCHEMA = 1,
REQ_DATA = 2,
REQ_ALL = REQ_SCHEMA + REQ_DATA
} teReqs;
const char *progname; const char *progname;
static char *modulename = gettext_noop("archiver"); static char *modulename = gettext_noop("archiver");
...@@ -63,7 +56,7 @@ static void _becomeOwner(ArchiveHandle *AH, TocEntry *te); ...@@ -63,7 +56,7 @@ static void _becomeOwner(ArchiveHandle *AH, TocEntry *te);
static void _selectOutputSchema(ArchiveHandle *AH, const char *schemaName); static void _selectOutputSchema(ArchiveHandle *AH, const char *schemaName);
static void _selectTablespace(ArchiveHandle *AH, const char *tablespace); static void _selectTablespace(ArchiveHandle *AH, const char *tablespace);
static teReqs _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool acl_pass); static teReqs _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool include_acls);
static void _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt); static void _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
static void _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt); static void _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
static TocEntry *getTocEntryByDumpId(ArchiveHandle *AH, DumpId id); static TocEntry *getTocEntryByDumpId(ArchiveHandle *AH, DumpId id);
...@@ -135,7 +128,6 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) ...@@ -135,7 +128,6 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
TocEntry *te = AH->toc->next; TocEntry *te = AH->toc->next;
teReqs reqs; teReqs reqs;
OutputContext sav; OutputContext sav;
int impliedDataOnly;
bool defnDumped; bool defnDumped;
AH->ropt = ropt; AH->ropt = ropt;
...@@ -188,17 +180,16 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) ...@@ -188,17 +180,16 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
*/ */
if (!ropt->dataOnly) if (!ropt->dataOnly)
{ {
te = AH->toc->next; int impliedDataOnly = 1;
impliedDataOnly = 1;
while (te != AH->toc) for (te = AH->toc->next; te != AH->toc; te = te->next)
{ {
reqs = _tocEntryRequired(te, ropt, false); reqs = _tocEntryRequired(te, ropt, true);
if ((reqs & REQ_SCHEMA) != 0) if ((reqs & REQ_SCHEMA) != 0)
{ /* It's schema, and it's wanted */ { /* It's schema, and it's wanted */
impliedDataOnly = 0; impliedDataOnly = 0;
break; break;
} }
te = te->next;
} }
if (impliedDataOnly) if (impliedDataOnly)
{ {
...@@ -232,7 +223,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) ...@@ -232,7 +223,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
while (te != AH->toc) while (te != AH->toc)
{ {
reqs = _tocEntryRequired(te, ropt, false); reqs = _tocEntryRequired(te, ropt, false /* needn't drop ACLs */);
if (((reqs & REQ_SCHEMA) != 0) && te->dropStmt) if (((reqs & REQ_SCHEMA) != 0) && te->dropStmt)
{ {
/* We want the schema */ /* We want the schema */
...@@ -248,7 +239,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) ...@@ -248,7 +239,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
} }
/* /*
* Now process each TOC entry * Now process each non-ACL TOC entry
*/ */
te = AH->toc->next; te = AH->toc->next;
while (te != AH->toc) while (te != AH->toc)
...@@ -709,7 +700,7 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt) ...@@ -709,7 +700,7 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
while (te != AH->toc) while (te != AH->toc)
{ {
if (_tocEntryRequired(te, ropt, false) != 0) if (_tocEntryRequired(te, ropt, true) != 0)
ahprintf(AH, "%d; %u %u %s %s %s %s\n", te->dumpId, ahprintf(AH, "%d; %u %u %s %s %s %s\n", te->dumpId,
te->catalogId.tableoid, te->catalogId.oid, te->catalogId.tableoid, te->catalogId.oid,
te->desc, te->namespace ? te->namespace : "-", te->desc, te->namespace ? te->namespace : "-",
...@@ -1341,7 +1332,7 @@ getTocEntryByDumpId(ArchiveHandle *AH, DumpId id) ...@@ -1341,7 +1332,7 @@ getTocEntryByDumpId(ArchiveHandle *AH, DumpId id)
return NULL; return NULL;
} }
int teReqs
TocIDRequired(ArchiveHandle *AH, DumpId id, RestoreOptions *ropt) TocIDRequired(ArchiveHandle *AH, DumpId id, RestoreOptions *ropt)
{ {
TocEntry *te = getTocEntryByDumpId(AH, id); TocEntry *te = getTocEntryByDumpId(AH, id);
...@@ -1349,7 +1340,7 @@ TocIDRequired(ArchiveHandle *AH, DumpId id, RestoreOptions *ropt) ...@@ -1349,7 +1340,7 @@ TocIDRequired(ArchiveHandle *AH, DumpId id, RestoreOptions *ropt)
if (!te) if (!te)
return 0; return 0;
return _tocEntryRequired(te, ropt, false); return _tocEntryRequired(te, ropt, true);
} }
size_t size_t
...@@ -1971,16 +1962,16 @@ ReadToc(ArchiveHandle *AH) ...@@ -1971,16 +1962,16 @@ ReadToc(ArchiveHandle *AH)
} }
static teReqs static teReqs
_tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool acl_pass) _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool include_acls)
{ {
teReqs res = 3; /* Schema = 1, Data = 2, Both = 3 */ teReqs res = REQ_ALL;
/* ENCODING objects are dumped specially, so always reject here */ /* ENCODING objects are dumped specially, so always reject here */
if (strcmp(te->desc, "ENCODING") == 0) if (strcmp(te->desc, "ENCODING") == 0)
return 0; return 0;
/* If it's an ACL, maybe ignore it */ /* If it's an ACL, maybe ignore it */
if ((!acl_pass || ropt->aclsSkip) && strcmp(te->desc, "ACL") == 0) if ((!include_acls || ropt->aclsSkip) && strcmp(te->desc, "ACL") == 0)
return 0; return 0;
if (!ropt->create && strcmp(te->desc, "DATABASE") == 0) if (!ropt->create && strcmp(te->desc, "DATABASE") == 0)
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.62 2004/11/06 19:36:01 tgl Exp $ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.63 2005/01/25 22:44:31 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -164,6 +164,13 @@ typedef enum ...@@ -164,6 +164,13 @@ typedef enum
STAGE_FINALIZING STAGE_FINALIZING
} ArchiverStage; } ArchiverStage;
typedef enum
{
REQ_SCHEMA = 1,
REQ_DATA = 2,
REQ_ALL = REQ_SCHEMA + REQ_DATA
} teReqs;
typedef struct _archiveHandle typedef struct _archiveHandle
{ {
Archive public; /* Public part of archive */ Archive public; /* Public part of archive */
...@@ -321,7 +328,7 @@ extern void WriteToc(ArchiveHandle *AH); ...@@ -321,7 +328,7 @@ extern void WriteToc(ArchiveHandle *AH);
extern void ReadToc(ArchiveHandle *AH); extern void ReadToc(ArchiveHandle *AH);
extern void WriteDataChunks(ArchiveHandle *AH); extern void WriteDataChunks(ArchiveHandle *AH);
extern int TocIDRequired(ArchiveHandle *AH, DumpId id, RestoreOptions *ropt); extern teReqs TocIDRequired(ArchiveHandle *AH, DumpId id, RestoreOptions *ropt);
extern bool checkSeek(FILE *fp); extern bool checkSeek(FILE *fp);
/* /*
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.29 2004/03/03 21:28:54 tgl Exp $ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.30 2005/01/25 22:44:31 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -442,7 +442,7 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt) ...@@ -442,7 +442,7 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
while (id != te->dumpId) while (id != te->dumpId)
{ {
if ((TocIDRequired(AH, id, ropt) & 2) != 0) if ((TocIDRequired(AH, id, ropt) & REQ_DATA) != 0)
die_horribly(AH, modulename, die_horribly(AH, modulename,
"Dumping a specific TOC data block out of order is not supported" "Dumping a specific TOC data block out of order is not supported"
" without ID on this input stream (fseek required)\n"); " without ID on this input stream (fseek required)\n");
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.46 2004/11/29 03:01:54 momjian Exp $ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.47 2005/01/25 22:44:31 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1120,7 +1120,7 @@ _tarPositionTo(ArchiveHandle *AH, const char *filename) ...@@ -1120,7 +1120,7 @@ _tarPositionTo(ArchiveHandle *AH, const char *filename)
ahlog(AH, 4, "skipping tar member %s\n", th->targetFile); ahlog(AH, 4, "skipping tar member %s\n", th->targetFile);
id = atoi(th->targetFile); id = atoi(th->targetFile);
if ((TocIDRequired(AH, id, AH->ropt) & 2) != 0) if ((TocIDRequired(AH, id, AH->ropt) & REQ_DATA) != 0)
die_horribly(AH, modulename, "dumping data out of order is not supported in this archive format: " die_horribly(AH, modulename, "dumping data out of order is not supported in this archive format: "
"%s is required, but comes before %s in the archive file.\n", "%s is required, but comes before %s in the archive file.\n",
th->targetFile, filename); th->targetFile, filename);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment