Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit cad4323

Browse files
Refactor check_ functions to use filehandle for status
When reporting failure in check_ functions there is (typically) a text- file mentioned in the error report which contains further details. Some check_ functions kept a separate flag variable to indicate failure, and some just checked the state of the filehandle as it's guaranteed to be open when the check failed. This refactors the functions to consistently do the same check on error reporting. As the error report contains the filepath, it makes more sense to check the filehandle state and skip the flag variable. Reviewed-by: Nathan Bossart <nathandbossart@gmail.com> Reviewed-by: Bruce Momjian <bruce@momjian.us> Discussion: https://postgr.es/m/595759F6-625B-4ED7-8125-91AF00437F83@yesql.se
1 parent 7d5852c commit cad4323

File tree

3 files changed

+7
-34
lines changed

3 files changed

+7
-34
lines changed

src/bin/pg_upgrade/check.c

+5-25
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,6 @@ check_proper_datallowconn(ClusterInfo *cluster)
711711
int i_datallowconn;
712712
FILE *script = NULL;
713713
char output_path[MAXPGPATH];
714-
bool found = false;
715714

716715
prep_status("Checking database connection settings");
717716

@@ -750,7 +749,6 @@ check_proper_datallowconn(ClusterInfo *cluster)
750749
*/
751750
if (strcmp(datallowconn, "f") == 0)
752751
{
753-
found = true;
754752
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
755753
pg_fatal("could not open file \"%s\": %s",
756754
output_path, strerror(errno));
@@ -765,10 +763,8 @@ check_proper_datallowconn(ClusterInfo *cluster)
765763
PQfinish(conn_template1);
766764

767765
if (script)
768-
fclose(script);
769-
770-
if (found)
771766
{
767+
fclose(script);
772768
pg_log(PG_REPORT, "fatal");
773769
pg_fatal("All non-template0 databases must allow connections, i.e. their\n"
774770
"pg_database.datallowconn must be true. Your installation contains\n"
@@ -829,7 +825,6 @@ check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster)
829825
{
830826
int dbnum;
831827
FILE *script = NULL;
832-
bool found = false;
833828
char output_path[MAXPGPATH];
834829

835830
prep_status("Checking for contrib/isn with bigint-passing mismatch");
@@ -870,7 +865,6 @@ check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster)
870865
i_proname = PQfnumber(res, "proname");
871866
for (rowno = 0; rowno < ntups; rowno++)
872867
{
873-
found = true;
874868
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
875869
pg_fatal("could not open file \"%s\": %s",
876870
output_path, strerror(errno));
@@ -890,10 +884,8 @@ check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster)
890884
}
891885

892886
if (script)
893-
fclose(script);
894-
895-
if (found)
896887
{
888+
fclose(script);
897889
pg_log(PG_REPORT, "fatal");
898890
pg_fatal("Your installation contains \"contrib/isn\" functions which rely on the\n"
899891
"bigint data type. Your old and new clusters pass bigint values\n"
@@ -915,7 +907,6 @@ check_for_user_defined_postfix_ops(ClusterInfo *cluster)
915907
{
916908
int dbnum;
917909
FILE *script = NULL;
918-
bool found = false;
919910
char output_path[MAXPGPATH];
920911

921912
prep_status("Checking for user-defined postfix operators");
@@ -968,7 +959,6 @@ check_for_user_defined_postfix_ops(ClusterInfo *cluster)
968959
i_typname = PQfnumber(res, "typname");
969960
for (rowno = 0; rowno < ntups; rowno++)
970961
{
971-
found = true;
972962
if (script == NULL &&
973963
(script = fopen_priv(output_path, "w")) == NULL)
974964
pg_fatal("could not open file \"%s\": %s",
@@ -992,10 +982,8 @@ check_for_user_defined_postfix_ops(ClusterInfo *cluster)
992982
}
993983

994984
if (script)
995-
fclose(script);
996-
997-
if (found)
998985
{
986+
fclose(script);
999987
pg_log(PG_REPORT, "fatal");
1000988
pg_fatal("Your installation contains user-defined postfix operators, which are not\n"
1001989
"supported anymore. Consider dropping the postfix operators and replacing\n"
@@ -1145,7 +1133,6 @@ check_for_tables_with_oids(ClusterInfo *cluster)
11451133
{
11461134
int dbnum;
11471135
FILE *script = NULL;
1148-
bool found = false;
11491136
char output_path[MAXPGPATH];
11501137

11511138
prep_status("Checking for tables WITH OIDS");
@@ -1179,7 +1166,6 @@ check_for_tables_with_oids(ClusterInfo *cluster)
11791166
i_relname = PQfnumber(res, "relname");
11801167
for (rowno = 0; rowno < ntups; rowno++)
11811168
{
1182-
found = true;
11831169
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
11841170
pg_fatal("could not open file \"%s\": %s",
11851171
output_path, strerror(errno));
@@ -1199,10 +1185,8 @@ check_for_tables_with_oids(ClusterInfo *cluster)
11991185
}
12001186

12011187
if (script)
1202-
fclose(script);
1203-
1204-
if (found)
12051188
{
1189+
fclose(script);
12061190
pg_log(PG_REPORT, "fatal");
12071191
pg_fatal("Your installation contains tables declared WITH OIDS, which is not\n"
12081192
"supported anymore. Consider removing the oid column using\n"
@@ -1401,7 +1385,6 @@ check_for_user_defined_encoding_conversions(ClusterInfo *cluster)
14011385
{
14021386
int dbnum;
14031387
FILE *script = NULL;
1404-
bool found = false;
14051388
char output_path[MAXPGPATH];
14061389

14071390
prep_status("Checking for user-defined encoding conversions");
@@ -1441,7 +1424,6 @@ check_for_user_defined_encoding_conversions(ClusterInfo *cluster)
14411424
i_nspname = PQfnumber(res, "nspname");
14421425
for (rowno = 0; rowno < ntups; rowno++)
14431426
{
1444-
found = true;
14451427
if (script == NULL &&
14461428
(script = fopen_priv(output_path, "w")) == NULL)
14471429
pg_fatal("could not open file \"%s\": %s",
@@ -1463,10 +1445,8 @@ check_for_user_defined_encoding_conversions(ClusterInfo *cluster)
14631445
}
14641446

14651447
if (script)
1466-
fclose(script);
1467-
1468-
if (found)
14691448
{
1449+
fclose(script);
14701450
pg_log(PG_REPORT, "fatal");
14711451
pg_fatal("Your installation contains user-defined encoding conversions.\n"
14721452
"The conversion function parameters changed in PostgreSQL version 14\n"

src/bin/pg_upgrade/function.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ check_loadable_libraries(void)
123123
int libnum;
124124
int was_load_failure = false;
125125
FILE *script = NULL;
126-
bool found = false;
127126
char output_path[MAXPGPATH];
128127

129128
prep_status("Checking for presence of required libraries");
@@ -158,7 +157,6 @@ check_loadable_libraries(void)
158157

159158
if (PQresultStatus(res) != PGRES_COMMAND_OK)
160159
{
161-
found = true;
162160
was_load_failure = true;
163161

164162
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
@@ -181,7 +179,7 @@ check_loadable_libraries(void)
181179

182180
PQfinish(conn);
183181

184-
if (found)
182+
if (script)
185183
{
186184
fclose(script);
187185
pg_log(PG_REPORT, "fatal");

src/bin/pg_upgrade/version.c

+1-6
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ report_extension_updates(ClusterInfo *cluster)
391391
{
392392
int dbnum;
393393
FILE *script = NULL;
394-
bool found = false;
395394
char *output_path = "update_extensions.sql";
396395

397396
prep_status("Checking for extension updates");
@@ -417,8 +416,6 @@ report_extension_updates(ClusterInfo *cluster)
417416
i_name = PQfnumber(res, "name");
418417
for (rowno = 0; rowno < ntups; rowno++)
419418
{
420-
found = true;
421-
422419
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
423420
pg_fatal("could not open file \"%s\": %s", output_path,
424421
strerror(errno));
@@ -442,10 +439,8 @@ report_extension_updates(ClusterInfo *cluster)
442439
}
443440

444441
if (script)
445-
fclose(script);
446-
447-
if (found)
448442
{
443+
fclose(script);
449444
report_status(PG_REPORT, "notice");
450445
pg_log(PG_REPORT, "\n"
451446
"Your installation contains extensions that should be updated\n"

0 commit comments

Comments
 (0)