From 7f1aeb726409b451faae61e20f9164b225bee535 Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Date: Tue, 4 Oct 2022 07:06:02 +0000
Subject: [PATCH v2] Use XLogFileNameById() in pg_upgrade/controldata.c

Use XLogFileNameById() in pg_upgrade/controldata.c instead of
explicit code to be consistent across the code base. Note that
this requires us to change the nextxlogfile size from hard-coded
25 bytes to MAXFNAMELEN (64 bytes).
---
 src/bin/pg_upgrade/controldata.c | 4 ++--
 src/bin/pg_upgrade/pg_upgrade.h  | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c
index 018cd310f7..b0b9da85d4 100644
--- a/src/bin/pg_upgrade/controldata.c
+++ b/src/bin/pg_upgrade/controldata.c
@@ -549,8 +549,8 @@ get_control_data(ClusterInfo *cluster, bool live_check)
 	{
 		if (got_tli && got_log_id && got_log_seg)
 		{
-			snprintf(cluster->controldata.nextxlogfile, 25, "%08X%08X%08X",
-					 tli, logid, segno);
+			XLogFileNameById(cluster->controldata.nextxlogfile, tli, logid,
+							 segno);
 			got_nextxlogfile = true;
 		}
 	}
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index 31589b0fdc..69fa7f4b64 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -10,6 +10,7 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 
+#include "access/xlog_internal.h"
 #include "common/relpath.h"
 #include "libpq-fe.h"
 
@@ -198,7 +199,7 @@ typedef struct
 {
 	uint32		ctrl_ver;
 	uint32		cat_ver;
-	char		nextxlogfile[25];
+	char		nextxlogfile[MAXFNAMELEN];
 	uint32		chkpnt_nxtxid;
 	uint32		chkpnt_nxtepoch;
 	uint32		chkpnt_nxtoid;
-- 
2.34.1

