From a421ed09c07d4116a456b56714e80297941eda0a Mon Sep 17 00:00:00 2001 From: jian he Date: Thu, 1 Jan 2026 13:25:33 +0800 Subject: [PATCH v12 1/1] run pgindent for run pgindent for v12_09122025-Non-text-modes-for-pg_dumpall-correspondingly-change.patch --- src/bin/pg_dump/pg_backup_archiver.c | 9 ++- src/bin/pg_dump/pg_dumpall.c | 107 ++++++++++++++------------- src/bin/pg_dump/pg_restore.c | 68 ++++++++--------- 3 files changed, 95 insertions(+), 89 deletions(-) diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 9ef78bf2b1e..c385d42e406 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -86,7 +86,7 @@ static int RestoringToDB(ArchiveHandle *AH); static void dump_lo_buf(ArchiveHandle *AH); static void dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim); static void SetOutput(ArchiveHandle *AH, const char *filename, - const pg_compress_specification compression_spec, bool append_data); + const pg_compress_specification compression_spec, bool append_data); static CompressFileHandle *SaveOutput(ArchiveHandle *AH); static void RestoreOutput(ArchiveHandle *AH, CompressFileHandle *savedOutput); @@ -772,12 +772,13 @@ RestoreArchive(Archive *AHX, bool append_data, bool globals_only) /* Skip for CONNECT meta command. */ if (!ropt->filename && te && te->tag && - (strcmp(te->tag, "CONNECT") == 0)) + (strcmp(te->tag, "CONNECT") == 0)) continue; /* Skip if no-tablespace is given. */ - if (ropt->noTablespace && te && te->tag && ((strcmp(te->tag, "dumpTablespaces") == 0) || - (strcmp(te->tag, "dropTablespaces") == 0))) + if (ropt->noTablespace && te && te->tag && + ((strcmp(te->tag, "dumpTablespaces") == 0) || + (strcmp(te->tag, "dropTablespaces") == 0))) continue; switch (_tocEntryRestorePass(te)) diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 8d4aac157ac..791d8bb3228 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -68,7 +68,7 @@ static void dropDBs(PGconn *conn); static void dumpUserConfig(PGconn *conn, const char *username); static void dumpDatabases(PGconn *conn, bool output_clean); static void dumpTimestamp(const char *msg); -static int runPgDump(const char *dbname, const char *create_opts, char *dbfile); +static int runPgDump(const char *dbname, const char *create_opts, char *dbfile); static void buildShSecLabels(PGconn *conn, const char *catalog_name, Oid objectId, const char *objtype, const char *objname, @@ -78,7 +78,7 @@ static void expand_dbname_patterns(PGconn *conn, SimpleStringList *patterns, SimpleStringList *names); static void read_dumpall_filters(const char *filename, SimpleStringList *pattern); static ArchiveFormat parseDumpFormat(const char *format); -static int createDumpId(void); +static int createDumpId(void); static void createOneArchiveEntry(const char *query, const char *tag); static char pg_dump_bin[MAXPGPATH]; @@ -128,7 +128,7 @@ static SimpleStringList database_exclude_names = {NULL, NULL}; static char *restrict_key; static Archive *fout = NULL; static pg_compress_specification compression_spec = {0}; -static int dumpIdVal = 0; +static int dumpIdVal = 0; static ArchiveFormat archDumpFormat = archNull; int @@ -460,7 +460,7 @@ main(int argc, char *argv[]) (!filename || strcmp(filename, "") == 0)) { pg_log_error("option %s=d|c|t requires option %s", - "-F/--format", "-f/--file"); + "-F/--format", "-f/--file"); pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit_nicely(1); } @@ -468,7 +468,7 @@ main(int argc, char *argv[]) /* restrict-key is only supported with --format=plain */ if (archDumpFormat != archNull && restrict_key) pg_fatal("option %s can only be used with %s=plain", - "--restrict-key", "--format"); + "--restrict-key", "--format"); /* * If password values are not required in the dump, switch to using @@ -640,19 +640,19 @@ main(int argc, char *argv[]) /* create a archive file for global commands. */ if (filename && archDumpFormat != archNull) { - char global_path[MAXPGPATH]; + char global_path[MAXPGPATH]; /* Set file path for global sql commands. */ snprintf(global_path, MAXPGPATH, "%s/toc.glo", filename); /* Open the output file */ fout = CreateArchive(global_path, archCustom, compression_spec, - dosync, archModeWrite, NULL, DATA_DIR_SYNC_METHOD_FSYNC); + dosync, archModeWrite, NULL, DATA_DIR_SYNC_METHOD_FSYNC); /* Make dump options accessible right away */ SetArchiveOptions(fout, &dopt, NULL); - ((ArchiveHandle*)fout)->connection = conn; - ((ArchiveHandle*)fout)->public.numWorkers = 1; + ((ArchiveHandle *) fout)->connection = conn; + ((ArchiveHandle *) fout)->public.numWorkers = 1; /* Register the cleanup hook */ on_exit_close_archive(fout); @@ -661,8 +661,9 @@ main(int argc, char *argv[]) fout->verbose = verbose; /* - * We allow the server to be back to 9.2, and up to any minor release of - * our own major version. (See also version check in pg_dumpall.c.) + * We allow the server to be back to 9.2, and up to any minor release + * of our own major version. (See also version check in + * pg_dumpall.c.) */ fout->minRemoteVersion = 90200; fout->maxRemoteVersion = (PG_VERSION_NUM / 100) * 100 + 99; @@ -694,14 +695,17 @@ main(int argc, char *argv[]) destroyPQExpBuffer(qry); } - /* dumpStdStrings: put the correct escape string behavior into the archive */ + /* + * dumpStdStrings: put the correct escape string behavior into the + * archive + */ { const char *stdstrings = std_strings ? "on" : "off"; PQExpBuffer qry = createPQExpBuffer(); pg_log_info("saving \"standard_conforming_strings = %s\"", stdstrings); appendPQExpBuffer(qry, "SET standard_conforming_strings = '%s';\n", - stdstrings); + stdstrings); createOneArchiveEntry(qry->data, "STDSTRINGS"); destroyPQExpBuffer(qry); } @@ -711,20 +715,20 @@ main(int argc, char *argv[]) fprintf(OPF, "--\n-- PostgreSQL database cluster dump\n--\n\n"); /* - * Enter restricted mode to block any unexpected psql meta-commands. A + * Enter restricted mode to block any unexpected psql meta-commands. A * malicious source might try to inject a variety of things via bogus * responses to queries. While we cannot prevent such sources from * affecting the destination at restore time, we can block psql - * meta-commands so that the client machine that runs psql with the dump - * output remains unaffected. + * meta-commands so that the client machine that runs psql with the + * dump output remains unaffected. */ fprintf(OPF, "\\restrict %s\n\n", restrict_key); /* * We used to emit \connect postgres here, but that served no purpose * other than to break things for installations without a postgres - * database. Everything we're restoring here is a global, so whichever - * database we're connected to at the moment is fine. + * database. Everything we're restoring here is a global, so + * whichever database we're connected to at the moment is fine. */ /* Restore will need to write to the target cluster */ @@ -784,8 +788,8 @@ main(int argc, char *argv[]) if (archDumpFormat == archNull) { /* - * Exit restricted mode just before dumping the databases. pg_dump will - * handle entering restricted mode again as appropriate. + * Exit restricted mode just before dumping the databases. pg_dump + * will handle entering restricted mode again as appropriate. */ fprintf(OPF, "\\unrestrict %s\n\n", restrict_key); } @@ -945,8 +949,8 @@ dropRoles(PGconn *conn) rolename = PQgetvalue(res, i, i_rolname); appendPQExpBuffer(delQry, "DROP ROLE %s%s;\n", - if_exists ? "IF EXISTS " : "", - fmtId(rolename)); + if_exists ? "IF EXISTS " : "", + fmtId(rolename)); if (archDumpFormat == archNull) fprintf(OPF, "%s", delQry->data); @@ -1534,8 +1538,8 @@ dropTablespaces(PGconn *conn) char *spcname = PQgetvalue(res, i, 0); appendPQExpBuffer(delQry, "DROP TABLESPACE %s%s;\n", - if_exists ? "IF EXISTS " : "", - fmtId(spcname)); + if_exists ? "IF EXISTS " : "", + fmtId(spcname)); if (archDumpFormat == archNull) fprintf(OPF, "%s", delQry->data); @@ -1706,8 +1710,8 @@ dropDBs(PGconn *conn) PQExpBuffer delQry = createPQExpBuffer(); appendPQExpBuffer(delQry, "DROP DATABASE %s%s;\n", - if_exists ? "IF EXISTS " : "", - fmtId(dbname)); + if_exists ? "IF EXISTS " : "", + fmtId(dbname)); if (archDumpFormat == archNull) fprintf(OPF, "%s", delQry->data); @@ -1751,7 +1755,7 @@ dumpUserConfig(PGconn *conn, const char *username) fprintf(OPF, "\n--\n-- User Config \"%s\"\n--\n\n", sanitized); else { - PQExpBuffer qry = createPQExpBuffer(); + PQExpBuffer qry = createPQExpBuffer(); appendPQExpBuffer(qry, "\n--\n-- User Config \"%s\"\n--\n\n", sanitized); createOneArchiveEntry(qry->data, "COMMENT"); @@ -1843,7 +1847,7 @@ dumpDatabases(PGconn *conn, bool output_clean) int i; char db_subdir[MAXPGPATH]; char dbfilepath[MAXPGPATH]; - FILE *map_file = NULL; + FILE *map_file = NULL; /* * Skip databases marked not datallowconn, since we'd be unable to connect @@ -1876,29 +1880,29 @@ dumpDatabases(PGconn *conn, bool output_clean) * under the main directory and each database dump file or subdirectory * will be created in that subdirectory by pg_dump. */ - if (archDumpFormat != archNull) - { - char map_file_path[MAXPGPATH]; + if (archDumpFormat != archNull) + { + char map_file_path[MAXPGPATH]; - snprintf(db_subdir, MAXPGPATH, "%s/databases", filename); + snprintf(db_subdir, MAXPGPATH, "%s/databases", filename); - /* Create a subdirectory with 'databases' name under main directory. */ - if (mkdir(db_subdir, pg_dir_create_mode) != 0) - pg_fatal("could not create directory \"%s\": %m", db_subdir); + /* Create a subdirectory with 'databases' name under main directory. */ + if (mkdir(db_subdir, pg_dir_create_mode) != 0) + pg_fatal("could not create directory \"%s\": %m", db_subdir); - snprintf(map_file_path, MAXPGPATH, "%s/map.dat", filename); + snprintf(map_file_path, MAXPGPATH, "%s/map.dat", filename); - /* Create a map file (to store dboid and dbname) */ - map_file = fopen(map_file_path, PG_BINARY_W); - if (!map_file) - pg_fatal("could not open file \"%s\": %m", map_file_path); - } + /* Create a map file (to store dboid and dbname) */ + map_file = fopen(map_file_path, PG_BINARY_W); + if (!map_file) + pg_fatal("could not open file \"%s\": %m", map_file_path); + } for (i = 0; i < PQntuples(res); i++) { char *dbname = PQgetvalue(res, i, 0); char *sanitized; - char *oid = PQgetvalue(res, i, 1); + char *oid = PQgetvalue(res, i, 1); const char *create_opts = ""; int ret; @@ -1947,7 +1951,7 @@ dumpDatabases(PGconn *conn, bool output_clean) fprintf(OPF, "\\connect %s\n\n", dbname); else { - PQExpBuffer qry = createPQExpBuffer(); + PQExpBuffer qry = createPQExpBuffer(); appendPQExpBuffer(qry, "\\connect %s\n\n", dbname); createOneArchiveEntry(qry->data, "CONNECT"); @@ -2019,7 +2023,7 @@ runPgDump(const char *dbname, const char *create_opts, char *dbfile) if (archDumpFormat != archNull) { printfPQExpBuffer(&cmd, "\"%s\" %s -f %s %s", pg_dump_bin, - pgdumpopts->data, dbfile, create_opts); + pgdumpopts->data, dbfile, create_opts); if (archDumpFormat == archDirectory) appendPQExpBufferStr(&cmd, " --format=directory "); @@ -2239,14 +2243,15 @@ createDumpId(void) static void createOneArchiveEntry(const char *query, const char *tag) { - CatalogId nilCatalogId = {0, 0}; + CatalogId nilCatalogId = {0, 0}; + Assert(fout != NULL); ArchiveEntry(fout, - nilCatalogId, /* catalog ID */ - createDumpId(), /* dump ID */ - ARCHIVE_OPTS(.tag = tag, - .description = tag, - .section = SECTION_PRE_DATA, - .createStmt = query)); + nilCatalogId, /* catalog ID */ + createDumpId(), /* dump ID */ + ARCHIVE_OPTS(.tag = tag, + .description = tag, + .section = SECTION_PRE_DATA, + .createStmt = query)); } diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c index f59813965bc..697f2f89d3e 100644 --- a/src/bin/pg_dump/pg_restore.c +++ b/src/bin/pg_dump/pg_restore.c @@ -62,11 +62,11 @@ static bool file_exists_in_directory(const char *dir, const char *filename); static int restore_one_database(const char *inputFileSpec, RestoreOptions *opts, int numWorkers, bool append_data, int num, bool globals_only); -static int restore_global_objects(const char *inputFileSpec, - RestoreOptions *opts, int numWorkers, - int num, bool globals_only); +static int restore_global_objects(const char *inputFileSpec, + RestoreOptions *opts, int numWorkers, + int num, bool globals_only); static int restore_all_databases(const char *inputFileSpec, - SimpleStringList db_exclude_patterns, RestoreOptions *opts, int numWorkers); + SimpleStringList db_exclude_patterns, RestoreOptions *opts, int numWorkers); static int get_dbnames_list_to_restore(PGconn *conn, SimplePtrList *dbname_oid_list, SimpleStringList db_exclude_patterns); @@ -82,7 +82,7 @@ typedef struct DbOidName { Oid oid; char str[FLEXIBLE_ARRAY_MEMBER]; /* null-terminated string here */ -} DbOidName; +} DbOidName; int @@ -389,7 +389,7 @@ main(int argc, char **argv) if (db_exclude_patterns.head != NULL && globals_only) { pg_log_error("option %s cannot be used together with %s", - "--exclude-database", "-g/--globals-only"); + "--exclude-database", "-g/--globals-only"); pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit_nicely(1); } @@ -469,7 +469,7 @@ main(int argc, char **argv) if (data_only && globals_only) pg_fatal("options %s and %s cannot be used together", - "-a/--data-only", "-g/--globals-only"); + "-a/--data-only", "-g/--globals-only"); /* * -C is not compatible with -1, because we can't create a database inside @@ -537,12 +537,11 @@ main(int argc, char **argv) } /* - * If toc.glo file is present, then restore all the - * databases from map.dat, but skip restoring those matching - * --exclude-database patterns. + * If toc.glo file is present, then restore all the databases from + * map.dat, but skip restoring those matching --exclude-database patterns. */ if (inputFileSpec != NULL && - (file_exists_in_directory(inputFileSpec, "toc.glo"))) + (file_exists_in_directory(inputFileSpec, "toc.glo"))) { /* * Can only use --list or --use-list options with a single database @@ -550,10 +549,10 @@ main(int argc, char **argv) */ if (opts->tocSummary) pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall", - "-l/--list"); + "-l/--list"); else if (opts->tocFile) pg_fatal("option %s cannot be used when restoring an archive created by pg_dumpall", - "-L/--use-list"); + "-L/--use-list"); /* * To restore from a pg_dumpall archive, -C (create database) option @@ -562,7 +561,7 @@ main(int argc, char **argv) if (!globals_only && opts->createDB != 1) { pg_log_error("option %s must be specified when restoring an archive created by pg_dumpall", - "-C/--create"); + "-C/--create"); pg_log_error_hint("Try \"%s --help\" for more information.", progname); pg_log_error_hint("Individual databases can be restored using their specific archives."); exit_nicely(1); @@ -571,14 +570,14 @@ main(int argc, char **argv) /* If globals-only, then return from here. */ if (globals_only) { - char global_path[MAXPGPATH]; + char global_path[MAXPGPATH]; /* Set path for toc.glo file. */ snprintf(global_path, MAXPGPATH, "%s/toc.glo", inputFileSpec); n_errors = restore_global_objects(global_path, opts, numWorkers, 0, globals_only); pg_log_info("database restoring skipped because option %s was specified", - "-g/--globals-only"); + "-g/--globals-only"); } else { @@ -596,16 +595,16 @@ main(int argc, char **argv) { simple_string_list_destroy(&db_exclude_patterns); pg_fatal("option %s can be used only when restoring an archive created by pg_dumpall", - "--exclude-database"); + "--exclude-database"); } if (globals_only) pg_fatal("option %s can be used only when restoring an archive created by pg_dumpall", - "-g/--globals-only"); + "-g/--globals-only"); /* Process if toc.glo file does not exist. */ n_errors = restore_one_database(inputFileSpec, opts, - numWorkers, false, 0, globals_only); + numWorkers, false, 0, globals_only); } /* Done, print a summary of ignored errors during restore. */ @@ -625,18 +624,19 @@ main(int argc, char **argv) * * If globals_only is set, then skip DROP DATABASE commands from restore. */ -static int restore_global_objects(const char *inputFileSpec, RestoreOptions *opts, - int numWorkers, int num, bool globals_only) +static int +restore_global_objects(const char *inputFileSpec, RestoreOptions *opts, + int numWorkers, int num, bool globals_only) { - int nerror = 0; - int format = opts->format; + int nerror = 0; + int format = opts->format; /* Set format as custom so that toc.glo file can be read. */ opts->format = archCustom; if (!data_only) nerror = restore_one_database(inputFileSpec, opts, numWorkers, - false, num, globals_only); + false, num, globals_only); /* Reset format value. */ opts->format = format; @@ -1020,8 +1020,8 @@ get_dbname_oid_list_from_mfile(const char *dumpdirpath, SimplePtrList *dbname_oi /* - * If there is no map.dat file in dump, then return from here as - * there is no database to restore. + * If there is no map.dat file in dump, then return from here as there is + * no database to restore. */ if (!file_exists_in_directory(dumpdirpath, "map.dat")) { @@ -1107,7 +1107,7 @@ restore_all_databases(const char *inputFileSpec, bool dumpData = opts->dumpData; bool dumpSchema = opts->dumpSchema; bool dumpStatistics = opts->dumpSchema; - PGconn *conn = NULL; + PGconn *conn = NULL; char global_path[MAXPGPATH]; /* Set path for toc.glo file. */ @@ -1137,8 +1137,8 @@ restore_all_databases(const char *inputFileSpec, if (opts->cparams.dbname) { conn = ConnectDatabase(opts->cparams.dbname, NULL, opts->cparams.pghost, - opts->cparams.pgport, opts->cparams.username, TRI_DEFAULT, - false, progname, NULL, NULL, NULL, NULL); + opts->cparams.pgport, opts->cparams.username, TRI_DEFAULT, + false, progname, NULL, NULL, NULL, NULL); if (!conn) pg_fatal("could not connect to database \"%s\"", opts->cparams.dbname); @@ -1149,8 +1149,8 @@ restore_all_databases(const char *inputFileSpec, pg_log_info("trying to connect to database \"%s\"", "postgres"); conn = ConnectDatabase("postgres", NULL, opts->cparams.pghost, - opts->cparams.pgport, opts->cparams.username, TRI_DEFAULT, - false, progname, NULL, NULL, NULL, NULL); + opts->cparams.pgport, opts->cparams.username, TRI_DEFAULT, + false, progname, NULL, NULL, NULL, NULL); /* Try with template1. */ if (!conn) @@ -1158,8 +1158,8 @@ restore_all_databases(const char *inputFileSpec, pg_log_info("trying to connect to database \"%s\"", "template1"); conn = ConnectDatabase("template1", NULL, opts->cparams.pghost, - opts->cparams.pgport, opts->cparams.username, TRI_DEFAULT, - false, progname, NULL, NULL, NULL, NULL); + opts->cparams.pgport, opts->cparams.username, TRI_DEFAULT, + false, progname, NULL, NULL, NULL, NULL); } } } @@ -1175,7 +1175,7 @@ restore_all_databases(const char *inputFileSpec, PQfinish(conn); /* Open toc.dat file and execute/append all the global sql commands. */ - n_errors_total = restore_global_objects(global_path, opts, numWorkers, 0, false); + n_errors_total = restore_global_objects(global_path, opts, numWorkers, 0, false); /* Exit if no db needs to be restored. */ if (dbname_oid_list.head == NULL || num_db_restore == 0) -- 2.34.1