From 14bdb3f13de16523609d838b725540af5e23ddd3 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Wed, 18 Jan 2023 11:15:48 +0900 Subject: Refactor code for restoring files via shell commands Presently, restore_command uses a different code path than archive_cleanup_command and recovery_end_command. These code paths are similar and can be easily combined, as long as it is possible to identify if a command should: - Issue a FATAL on signal. - Exit immediately on SIGTERM. While on it, this removes src/common/archive.c and its associated header. Since the introduction of c96de2c, BuildRestoreCommand() has become a simple wrapper of replace_percent_placeholders() able to call make_native_path(). This simplifies shell_restore.c as long as RestoreArchivedFile() includes a call to make_native_path(). Author: Nathan Bossart Reviewed-by: Andres Freund, Michael Paquier Discussion: https://postgr.es/m/20221227192449.GA3672473@nathanxps13 --- src/fe_utils/archive.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/fe_utils/archive.c') diff --git a/src/fe_utils/archive.c b/src/fe_utils/archive.c index eb1c930ae7..c1ce250c90 100644 --- a/src/fe_utils/archive.c +++ b/src/fe_utils/archive.c @@ -19,8 +19,8 @@ #include #include "access/xlog_internal.h" -#include "common/archive.h" #include "common/logging.h" +#include "common/percentrepl.h" #include "fe_utils/archive.h" @@ -41,13 +41,18 @@ RestoreArchivedFile(const char *path, const char *xlogfname, { char xlogpath[MAXPGPATH]; char *xlogRestoreCmd; + char *nativePath; int rc; struct stat stat_buf; snprintf(xlogpath, MAXPGPATH, "%s/" XLOGDIR "/%s", path, xlogfname); - xlogRestoreCmd = BuildRestoreCommand(restoreCommand, xlogpath, - xlogfname, NULL); + nativePath = pstrdup(xlogpath); + make_native_path(nativePath); + xlogRestoreCmd = replace_percent_placeholders(restoreCommand, + "restore_command", "fp", + xlogfname, nativePath); + pfree(nativePath); /* * Execute restore_command, which should copy the missing file from -- cgit v1.2.1