From dbfc44716596073b99e093a04e29e774a518f520 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Wed, 13 Mar 2024 12:06:44 -0400 Subject: [PATCH] Expose new function get_controlfile_by_exact_path(). This works just like get_controlfile(), but expects the path to the control file rather than the path to the data directory that contains the control file. This makes more sense in cases where the caller has already constructed the path to the control file itself. Amul Sul and Robert Haas, reviewed by Michael Paquier --- src/bin/pg_combinebackup/pg_combinebackup.c | 2 +- src/common/controldata_utils.c | 18 ++++++++++++++++-- src/include/common/controldata_utils.h | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/bin/pg_combinebackup/pg_combinebackup.c b/src/bin/pg_combinebackup/pg_combinebackup.c index 60e62d03b19..4197cfeadef 100644 --- a/src/bin/pg_combinebackup/pg_combinebackup.c +++ b/src/bin/pg_combinebackup/pg_combinebackup.c @@ -534,7 +534,7 @@ check_control_files(int n_backups, char **backup_dirs) controlpath = psprintf("%s/%s", backup_dirs[i], "global/pg_control"); pg_log_debug("reading \"%s\"", controlpath); - control_file = get_controlfile(backup_dirs[i], &crc_ok); + control_file = get_controlfile_by_exact_path(controlpath, &crc_ok); /* Control file contents not meaningful if CRC is bad. */ if (!crc_ok) diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c index 92e8fed6b2e..82309b25107 100644 --- a/src/common/controldata_utils.c +++ b/src/common/controldata_utils.c @@ -50,10 +50,25 @@ */ ControlFileData * get_controlfile(const char *DataDir, bool *crc_ok_p) +{ + char ControlFilePath[MAXPGPATH]; + + snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir); + + return get_controlfile_by_exact_path(ControlFilePath, crc_ok_p); +} + +/* + * get_controlfile_by_exact_path() + * + * As above, but the caller specifies the path to the control file itself, + * rather than the path to the data directory. + */ +ControlFileData * +get_controlfile_by_exact_path(const char *ControlFilePath, bool *crc_ok_p) { ControlFileData *ControlFile; int fd; - char ControlFilePath[MAXPGPATH]; pg_crc32c crc; int r; #ifdef FRONTEND @@ -64,7 +79,6 @@ get_controlfile(const char *DataDir, bool *crc_ok_p) Assert(crc_ok_p); ControlFile = palloc_object(ControlFileData); - snprintf(ControlFilePath, MAXPGPATH, "%s/global/pg_control", DataDir); #ifdef FRONTEND INIT_CRC32C(last_crc); diff --git a/src/include/common/controldata_utils.h b/src/include/common/controldata_utils.h index 04da70e87b2..6e263ce0de0 100644 --- a/src/include/common/controldata_utils.h +++ b/src/include/common/controldata_utils.h @@ -13,6 +13,8 @@ #include "catalog/pg_control.h" extern ControlFileData *get_controlfile(const char *DataDir, bool *crc_ok_p); +extern ControlFileData *get_controlfile_by_exact_path(const char *ControlFilePath, + bool *crc_ok_p); extern void update_controlfile(const char *DataDir, ControlFileData *ControlFile, bool do_sync); -- 2.39.5