Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcad4323

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. Somecheck_ functions kept a separate flag variable to indicate failure, andsome just checked the state of the filehandle as it's guaranteed to beopen when the check failed. This refactors the functions to consistentlydo the same check on error reporting. As the error report contains thefilepath, it makes more sense to check the filehandle state and skip theflag 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 parent7d5852c commitcad4323

File tree

3 files changed

+7
-34
lines changed

3 files changed

+7
-34
lines changed

‎src/bin/pg_upgrade/check.c

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,6 @@ check_proper_datallowconn(ClusterInfo *cluster)
711711
inti_datallowconn;
712712
FILE*script=NULL;
713713
charoutput_path[MAXPGPATH];
714-
boolfound= 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
intdbnum;
831827
FILE*script=NULL;
832-
boolfound= false;
833828
charoutput_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
intdbnum;
917909
FILE*script=NULL;
918-
boolfound= false;
919910
charoutput_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
intdbnum;
11471135
FILE*script=NULL;
1148-
boolfound= false;
11491136
charoutput_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
intdbnum;
14031387
FILE*script=NULL;
1404-
boolfound= false;
14051388
charoutput_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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ check_loadable_libraries(void)
123123
intlibnum;
124124
intwas_load_failure= false;
125125
FILE*script=NULL;
126-
boolfound= false;
127126
charoutput_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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ report_extension_updates(ClusterInfo *cluster)
391391
{
392392
intdbnum;
393393
FILE*script=NULL;
394-
boolfound= 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)

[8]ページ先頭

©2009-2025 Movatter.jp