From 22a18af9fa4bed32db50a600d1c2770c1e929fbd Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Fri, 9 Sep 2022 07:52:02 -0500
Subject: [PATCH 2/2] f

---
 src/bin/pg_upgrade/check.c      | 11 ++++-----
 src/bin/pg_upgrade/pg_upgrade.h |  2 +-
 src/bin/pg_upgrade/version.c    | 41 ++++++++++++++-------------------
 3 files changed, 22 insertions(+), 32 deletions(-)

diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c
index f1bc1e68868..dc722da910c 100644
--- a/src/bin/pg_upgrade/check.c
+++ b/src/bin/pg_upgrade/check.c
@@ -1328,15 +1328,12 @@ check_for_reg_data_type_usage(ClusterInfo *cluster)
 static void
 check_for_jsonb_9_4_usage(ClusterInfo *cluster)
 {
-	char		output_path[MAXPGPATH];
+	const char output_basename[] = "tables_using_jsonb.txt";
 
 	prep_status("Checking for incompatible \"jsonb\" data type");
 
-	snprintf(output_path, sizeof(output_path), "%s/%s",
-			 log_opts.basedir,
-			 "tables_using_jsonb.txt");
-
-	if (check_for_data_type_usage(cluster, "pg_catalog.jsonb", output_path))
+	if (check_for_data_type_usage(cluster, "pg_catalog.jsonb",
+				output_basename))
 	{
 		pg_log(PG_REPORT, "fatal");
 		pg_fatal("Your installation contains the \"jsonb\" data type in user tables.\n"
@@ -1344,7 +1341,7 @@ check_for_jsonb_9_4_usage(ClusterInfo *cluster)
 				 "cluster cannot currently be upgraded.  You can\n"
 				 "drop the problem columns and restart the upgrade.\n"
 				 "A list of the problem columns is in the file:\n"
-				 "    %s", output_path);
+				 "    %s/%s", log_opts.basedir, output_basename);
 	}
 	else
 		check_ok();
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index 60c3c8dd68e..0a1bdfca5b2 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -443,7 +443,7 @@ unsigned int str2uint(const char *str);
 
 bool		check_for_data_types_usage(ClusterInfo *cluster,
 									   const char *base_query,
-									   const char *output_path);
+									   const char *output_basename);
 bool		check_for_data_type_usage(ClusterInfo *cluster,
 									  const char *type_name,
 									  const char *output_path);
diff --git a/src/bin/pg_upgrade/version.c b/src/bin/pg_upgrade/version.c
index dc19fc6ec84..059bd9b1e1c 100644
--- a/src/bin/pg_upgrade/version.c
+++ b/src/bin/pg_upgrade/version.c
@@ -30,12 +30,16 @@
 bool
 check_for_data_types_usage(ClusterInfo *cluster,
 						   const char *base_query,
-						   const char *output_path)
+						   const char *output_basename)
 {
 	bool		found = false;
 	FILE	   *script = NULL;
 	int			dbnum;
 
+	char		output_path[MAXPGPATH];
+	snprintf(output_path, sizeof(output_path), "%s/%s", log_opts.basedir,
+			output_basename);
+
 	for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
 	{
 		DbInfo	   *active_db = &cluster->dbarr.dbs[dbnum];
@@ -152,7 +156,7 @@ check_for_data_types_usage(ClusterInfo *cluster,
 bool
 check_for_data_type_usage(ClusterInfo *cluster,
 						  const char *type_name,
-						  const char *output_path)
+						  const char *output_basename)
 {
 	bool		found;
 	char	   *base_query;
@@ -160,7 +164,7 @@ check_for_data_type_usage(ClusterInfo *cluster,
 	base_query = psprintf("SELECT '%s'::pg_catalog.regtype AS oid",
 						  type_name);
 
-	found = check_for_data_types_usage(cluster, base_query, output_path);
+	found = check_for_data_types_usage(cluster, base_query, output_basename);
 
 	free(base_query);
 
@@ -179,15 +183,11 @@ check_for_data_type_usage(ClusterInfo *cluster,
 void
 old_9_3_check_for_line_data_type_usage(ClusterInfo *cluster)
 {
-	char		output_path[MAXPGPATH];
+	const char output_basename[] = "tables_using_line.txt";
 
 	prep_status("Checking for incompatible \"line\" data type");
 
-	snprintf(output_path, sizeof(output_path), "%s/%s",
-			 log_opts.basedir,
-			 "tables_using_line.txt");
-
-	if (check_for_data_type_usage(cluster, "pg_catalog.line", output_path))
+	if (check_for_data_type_usage(cluster, "pg_catalog.line", output_basename))
 	{
 		pg_log(PG_REPORT, "fatal");
 		pg_fatal("Your installation contains the \"line\" data type in user tables.\n"
@@ -196,7 +196,7 @@ old_9_3_check_for_line_data_type_usage(ClusterInfo *cluster)
 				 "cluster cannot currently be upgraded.  You can\n"
 				 "drop the problem columns and restart the upgrade.\n"
 				 "A list of the problem columns is in the file:\n"
-				 "    %s", output_path);
+				 "    %s/%s", log_opts.basedir, output_basename);
 	}
 	else
 		check_ok();
@@ -219,15 +219,12 @@ old_9_3_check_for_line_data_type_usage(ClusterInfo *cluster)
 void
 old_9_6_check_for_unknown_data_type_usage(ClusterInfo *cluster)
 {
-	char		output_path[MAXPGPATH];
+	const char output_basename[] = "tables_using_unknown.txt";
 
 	prep_status("Checking for invalid \"unknown\" user columns");
 
-	snprintf(output_path, sizeof(output_path), "%s/%s",
-			 log_opts.basedir,
-			 "tables_using_unknown.txt");
-
-	if (check_for_data_type_usage(cluster, "pg_catalog.unknown", output_path))
+	if (check_for_data_type_usage(cluster, "pg_catalog.unknown",
+				output_basename))
 	{
 		pg_log(PG_REPORT, "fatal");
 		pg_fatal("Your installation contains the \"unknown\" data type in user tables.\n"
@@ -235,7 +232,7 @@ old_9_6_check_for_unknown_data_type_usage(ClusterInfo *cluster)
 				 "cluster cannot currently be upgraded.  You can\n"
 				 "drop the problem columns and restart the upgrade.\n"
 				 "A list of the problem columns is in the file:\n"
-				 "    %s", output_path);
+				 "    %s/%s", log_opts.basedir, output_basename);
 	}
 	else
 		check_ok();
@@ -364,16 +361,12 @@ old_9_6_invalidate_hash_indexes(ClusterInfo *cluster, bool check_mode)
 void
 old_11_check_for_sql_identifier_data_type_usage(ClusterInfo *cluster)
 {
-	char		output_path[MAXPGPATH];
+	const char output_basename[] = "tables_using_sql_identifier.txt";
 
 	prep_status("Checking for invalid \"sql_identifier\" user columns");
 
-	snprintf(output_path, sizeof(output_path), "%s/%s",
-			 log_opts.basedir,
-			 "tables_using_sql_identifier.txt");
-
 	if (check_for_data_type_usage(cluster, "information_schema.sql_identifier",
-								  output_path))
+								  output_basename))
 	{
 		pg_log(PG_REPORT, "fatal");
 		pg_fatal("Your installation contains the \"sql_identifier\" data type in user tables.\n"
@@ -381,7 +374,7 @@ old_11_check_for_sql_identifier_data_type_usage(ClusterInfo *cluster)
 				 "cluster cannot currently be upgraded.  You can\n"
 				 "drop the problem columns and restart the upgrade.\n"
 				 "A list of the problem columns is in the file:\n"
-				 "    %s", output_path);
+				 "    %s/%s", log_opts.basedir, output_basename);
 	}
 	else
 		check_ok();
-- 
2.17.1

