diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2006-10-14 23:07:22 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2006-10-14 23:07:22 +0000 |
commit | 1314983fd302bf53dbf5284145205dea44cb832c (patch) | |
tree | e6e9d5e9e50966e4631f72e929710ba77b6da3e8 /src/bin/pg_dump/pg_backup_archiver.c | |
parent | f58eac82eeb62635ea870b62654836fb4c331e91 (diff) |
Code review for --no-data-for-failed-tables patch. Instead of trashing
one of the program's core data structures, make use of the existing
ability to selectively exclude TOC items by ID. Slightly more code but
much less likely to create future maintenance problems.
Diffstat (limited to 'src/bin/pg_dump/pg_backup_archiver.c')
-rw-r--r-- | src/bin/pg_dump/pg_backup_archiver.c | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 32b6490e6e6..272ff5fb9d9 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.136 2006/10/04 00:30:05 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.137 2006/10/14 23:07:22 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -279,23 +279,27 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) defnDumped = true; /* - * If we could not create a table, ignore the respective TABLE - * DATA if -X no-data-for-failed-tables is given + * If we could not create a table and --no-data-for-failed-tables + * was given, ignore the corresponding TABLE DATA */ - if (ropt->noDataForFailedTables && AH->lastErrorTE == te && strcmp(te->desc, "TABLE") == 0) + if (ropt->noDataForFailedTables && + AH->lastErrorTE == te && + strcmp(te->desc, "TABLE") == 0) { - TocEntry *tes, - *last; + TocEntry *tes; - ahlog(AH, 1, "table %s could not be created, will not restore its data\n", te->tag); + ahlog(AH, 1, "table \"%s\" could not be created, will not restore its data\n", + te->tag); - for (last = te, tes = te->next; tes != AH->toc; last = tes, tes = tes->next) + for (tes = te->next; tes != AH->toc; tes = tes->next) { - if (strcmp(tes->desc, "TABLE DATA") == 0 && strcmp(tes->tag, te->tag) == 0 && - strcmp(tes->namespace ? tes->namespace : "", te->namespace ? te->namespace : "") == 0) + if (strcmp(tes->desc, "TABLE DATA") == 0 && + strcmp(tes->tag, te->tag) == 0 && + strcmp(tes->namespace ? tes->namespace : "", + te->namespace ? te->namespace : "") == 0) { - /* remove this node */ - last->next = tes->next; + /* mark it unwanted */ + ropt->idWanted[tes->dumpId - 1] = false; break; } } @@ -789,7 +793,6 @@ SortTocFromFile(Archive *AHX, RestoreOptions *ropt) /* Allocate space for the 'wanted' array, and init it */ ropt->idWanted = (bool *) malloc(sizeof(bool) * AH->maxDumpId); memset(ropt->idWanted, 0, sizeof(bool) * AH->maxDumpId); - ropt->limitToList = true; /* Set prev entry as head of list */ tePrev = AH->toc; @@ -837,6 +840,19 @@ SortTocFromFile(Archive *AHX, RestoreOptions *ropt) strerror(errno)); } +/* + * Set up a dummy ID filter that selects all dump IDs + */ +void +InitDummyWantedList(Archive *AHX, RestoreOptions *ropt) +{ + ArchiveHandle *AH = (ArchiveHandle *) AHX; + + /* Allocate space for the 'wanted' array, and init it to 1's */ + ropt->idWanted = (bool *) malloc(sizeof(bool) * AH->maxDumpId); + memset(ropt->idWanted, 1, sizeof(bool) * AH->maxDumpId); +} + /********************** * 'Convenience functions that look like standard IO functions * for writing data when in dump mode. @@ -2066,8 +2082,8 @@ _tocEntryRequired(TocEntry *te, RestoreOptions *ropt, bool include_acls) if (!te->defn || strlen(te->defn) == 0) res = res & ~REQ_SCHEMA; - /* Finally, if we used a list, limit based on that as well */ - if (ropt->limitToList && !ropt->idWanted[te->dumpId - 1]) + /* Finally, if there's a per-ID filter, limit based on that as well */ + if (ropt->idWanted && !ropt->idWanted[te->dumpId - 1]) return 0; return res; |