15
15
*
16
16
*
17
17
* 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 $
19
19
*
20
20
*-------------------------------------------------------------------------
21
21
*/
@@ -48,8 +48,7 @@ static char *modulename = gettext_noop("archiver");
48
48
static ArchiveHandle * _allocAH (const char * FileSpec , const ArchiveFormat fmt ,
49
49
const int compression , ArchiveMode mode );
50
50
static 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 );
53
52
54
53
55
54
static void fixPriorBlobRefs (ArchiveHandle * AH , TocEntry * blobte ,
@@ -379,14 +378,11 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
379
378
/* Work out what, if anything, we want from this entry */
380
379
reqs = _tocEntryRequired (te , ropt , true);
381
380
382
- defnDumped = false;
383
-
384
381
if ((reqs & REQ_SCHEMA ) != 0 ) /* We want the schema */
385
382
{
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 );
388
385
_printTocEntry (AH , te , ropt , false, true);
389
- defnDumped = true;
390
386
}
391
387
392
388
te = te -> next ;
@@ -2304,10 +2300,40 @@ _getObjectFromDropStmt(const char *dropStmt, const char *type)
2304
2300
}
2305
2301
2306
2302
static void
2307
- _printTocHeader (ArchiveHandle * AH , TocEntry * te , RestoreOptions * ropt , bool isData )
2303
+ _printTocEntry (ArchiveHandle * AH , TocEntry * te , RestoreOptions * ropt , bool isData , bool acl_pass )
2308
2304
{
2309
2305
const char * pfx ;
2310
2306
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 */
2311
2337
if (isData )
2312
2338
pfx = "Data for " ;
2313
2339
else
@@ -2335,64 +2361,48 @@ _printTocHeader(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDa
2335
2361
if (AH -> PrintExtraTocPtr != NULL )
2336
2362
(* AH -> PrintExtraTocPtr ) (AH , te );
2337
2363
ahprintf (AH , "--\n\n" );
2338
- }
2339
2364
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 )
2350
2373
{
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 );
2353
2375
}
2354
- else if (! acl_pass && strlen ( te -> defn ) > 0 )
2376
+ else
2355
2377
{
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 );
2393
2380
}
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 );
2396
2406
}
2397
2407
2398
2408
/*
@@ -2405,8 +2415,6 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
2405
2415
free (AH -> currUser );
2406
2416
AH -> currUser = NULL ;
2407
2417
}
2408
-
2409
- return 1 ;
2410
2418
}
2411
2419
2412
2420
void
0 commit comments