1515 *
1616 *
1717 * IDENTIFICATION
18- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.91 2004/08/04 17:13:03 tgl Exp $
18+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.92 2004/08/13 21:37:28 tgl Exp $
1919 *
2020 *-------------------------------------------------------------------------
2121 */
@@ -48,8 +48,7 @@ static char *modulename = gettext_noop("archiver");
4848static ArchiveHandle * _allocAH (const char * FileSpec , const ArchiveFormat fmt ,
4949 const int compression , ArchiveMode mode );
5050static char * _getObjectFromDropStmt (const char * dropStmt , const char * type );
51- static void _printTocHeader (ArchiveHandle * AH , TocEntry * te , RestoreOptions * ropt , bool isData );
52- static int _printTocEntry (ArchiveHandle * AH , TocEntry * te , RestoreOptions * ropt , bool isData , bool acl_pass );
51+ static void _printTocEntry (ArchiveHandle * AH , TocEntry * te , RestoreOptions * ropt , bool isData , bool acl_pass );
5352
5453
5554static void fixPriorBlobRefs (ArchiveHandle * AH , TocEntry * blobte ,
@@ -379,14 +378,11 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
379378 /* Work out what, if anything, we want from this entry */
380379 reqs = _tocEntryRequired (te , ropt , true);
381380
382- defnDumped = false;
383-
384381 if ((reqs & REQ_SCHEMA ) != 0 ) /* We want the schema */
385382 {
386- ahlog (AH , 1 , "setting owner and acl for %s %s\n" , te -> desc , te -> tag );
387-
383+ ahlog (AH , 1 , "setting owner and acl for %s %s\n" ,
384+ te -> desc , te -> tag );
388385 _printTocEntry (AH , te , ropt , false, true);
389- defnDumped = true;
390386 }
391387
392388 te = te -> next ;
@@ -2304,10 +2300,40 @@ _getObjectFromDropStmt(const char *dropStmt, const char *type)
23042300}
23052301
23062302static void
2307- _printTocHeader (ArchiveHandle * AH , TocEntry * te , RestoreOptions * ropt , bool isData )
2303+ _printTocEntry (ArchiveHandle * AH , TocEntry * te , RestoreOptions * ropt , bool isData , bool acl_pass )
23082304{
23092305 const char * pfx ;
23102306
2307+ /* ACLs are dumped only during acl pass */
2308+ if (acl_pass )
2309+ {
2310+ if (strcmp (te -> desc , "ACL" ) != 0 )
2311+ return ;
2312+ }
2313+ else
2314+ {
2315+ if (strcmp (te -> desc , "ACL" ) == 0 )
2316+ return ;
2317+ }
2318+
2319+ /*
2320+ * Avoid dumping the public schema, as it will already be created ...
2321+ * unless we are using --clean mode, in which case it's been deleted
2322+ * and we'd better recreate it.
2323+ */
2324+ if (!ropt -> dropSchema &&
2325+ strcmp (te -> desc , "SCHEMA" ) == 0 && strcmp (te -> tag , "public" ) == 0 )
2326+ return ;
2327+
2328+ /* Select owner and schema as necessary */
2329+ _becomeOwner (AH , te );
2330+ _selectOutputSchema (AH , te -> namespace );
2331+
2332+ /* Set up OID mode too */
2333+ if (strcmp (te -> desc , "TABLE" ) == 0 )
2334+ _setWithOids (AH , te );
2335+
2336+ /* Emit header comment for item */
23112337 if (isData )
23122338 pfx = "Data for " ;
23132339 else
@@ -2335,64 +2361,48 @@ _printTocHeader(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDa
23352361 if (AH -> PrintExtraTocPtr != NULL )
23362362 (* AH -> PrintExtraTocPtr ) (AH , te );
23372363 ahprintf (AH , "--\n\n" );
2338- }
23392364
2340- static int
2341- _printTocEntry (ArchiveHandle * AH , TocEntry * te , RestoreOptions * ropt , bool isData , bool acl_pass )
2342- {
2343- /* Select schema as necessary */
2344- _becomeOwner (AH , te );
2345- _selectOutputSchema (AH , te -> namespace );
2346- if (strcmp (te -> desc , "TABLE" ) == 0 && !acl_pass )
2347- _setWithOids (AH , te );
2348-
2349- if (acl_pass && strcmp (te -> desc , "ACL" ) == 0 )
2365+ /*
2366+ * Actually print the definition.
2367+ *
2368+ * Really crude hack for suppressing AUTHORIZATION clause of CREATE SCHEMA
2369+ * when --no-owner mode is selected. This is ugly, but I see no other
2370+ * good way ...
2371+ */
2372+ if (AH -> ropt && AH -> ropt -> noOwner && strcmp (te -> desc , "SCHEMA" ) == 0 )
23502373 {
2351- _printTocHeader (AH , te , ropt , isData );
2352- ahprintf (AH , "%s\n\n" , te -> defn );
2374+ ahprintf (AH , "CREATE SCHEMA %s;\n\n\n" , te -> tag );
23532375 }
2354- else if (! acl_pass && strlen ( te -> defn ) > 0 )
2376+ else
23552377 {
2356- _printTocHeader (AH , te , ropt , isData );
2357-
2358- /*
2359- * Really crude hack for suppressing AUTHORIZATION clause of CREATE SCHEMA
2360- * when --no-owner mode is selected. This is ugly, but I see no other
2361- * good way ... Also, avoid dumping the public schema as it will already be
2362- * created.
2363- */
2364- if (strcmp (te -> tag , "public" ) != 0 ) {
2365- if (AH -> ropt && AH -> ropt -> noOwner && strcmp (te -> desc , "SCHEMA" ) == 0 )
2366- {
2367- ahprintf (AH , "CREATE SCHEMA %s;\n\n\n" , te -> tag );
2368- }
2369- else
2370- {
2371- ahprintf (AH , "%s\n\n" , te -> defn );
2372-
2373- if (!ropt -> noOwner && !ropt -> use_setsessauth && strlen (te -> owner ) > 0 && strlen (te -> dropStmt ) > 0 && (
2374- strcmp (te -> desc , "AGGREGATE" ) == 0 ||
2375- strcmp (te -> desc , "CONVERSION" ) == 0 ||
2376- strcmp (te -> desc , "DOMAIN" ) == 0 ||
2377- strcmp (te -> desc , "FUNCTION" ) == 0 ||
2378- strcmp (te -> desc , "OPERATOR" ) == 0 ||
2379- strcmp (te -> desc , "OPERATOR CLASS" ) == 0 ||
2380- strcmp (te -> desc , "TABLE" ) == 0 ||
2381- strcmp (te -> desc , "TYPE" ) == 0 ||
2382- strcmp (te -> desc , "VIEW" ) == 0 ||
2383- strcmp (te -> desc , "SEQUENCE" ) == 0 ||
2384- (strcmp (te -> desc , "SCHEMA" ) == 0 && strcmp (te -> tag , "public" ) == 0 ) /* Only public schema */
2385- ))
2386- {
2387- char * temp = _getObjectFromDropStmt (te -> dropStmt , te -> desc );
2388- ahprintf (AH , "ALTER %s OWNER TO %s;\n\n" , temp , fmtId (te -> owner ));
2389- free (temp );
2390- }
2391- }
2392- }
2378+ if (strlen (te -> defn ) > 0 )
2379+ ahprintf (AH , "%s\n\n" , te -> defn );
23932380 }
2394- else if (isData ) {
2395- _printTocHeader (AH , te , ropt , isData );
2381+
2382+ /*
2383+ * If we aren't using SET SESSION AUTH to determine ownership, we must
2384+ * instead issue an ALTER OWNER command. Ugly, since we have to
2385+ * cons one up based on the dropStmt. We don't need this for schemas
2386+ * (since we use CREATE SCHEMA AUTHORIZATION instead), nor for some other
2387+ * object types.
2388+ */
2389+ if (!ropt -> noOwner && !ropt -> use_setsessauth &&
2390+ strlen (te -> owner ) > 0 && strlen (te -> dropStmt ) > 0 &&
2391+ (strcmp (te -> desc , "AGGREGATE" ) == 0 ||
2392+ strcmp (te -> desc , "CONVERSION" ) == 0 ||
2393+ strcmp (te -> desc , "DOMAIN" ) == 0 ||
2394+ strcmp (te -> desc , "FUNCTION" ) == 0 ||
2395+ strcmp (te -> desc , "OPERATOR" ) == 0 ||
2396+ strcmp (te -> desc , "OPERATOR CLASS" ) == 0 ||
2397+ strcmp (te -> desc , "TABLE" ) == 0 ||
2398+ strcmp (te -> desc , "TYPE" ) == 0 ||
2399+ strcmp (te -> desc , "VIEW" ) == 0 ||
2400+ strcmp (te -> desc , "SEQUENCE" ) == 0 ))
2401+ {
2402+ char * temp = _getObjectFromDropStmt (te -> dropStmt , te -> desc );
2403+
2404+ ahprintf (AH , "ALTER %s OWNER TO %s;\n\n" , temp , fmtId (te -> owner ));
2405+ free (temp );
23962406 }
23972407
23982408 /*
@@ -2405,8 +2415,6 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
24052415 free (AH -> currUser );
24062416 AH -> currUser = NULL ;
24072417 }
2408-
2409- return 1 ;
24102418}
24112419
24122420void
0 commit comments