aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xlogarchive.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2020-03-24 12:13:36 +0900
committerMichael Paquier <michael@paquier.xyz>2020-03-24 12:13:36 +0900
commite09ad07b21a244c3cbcdbe3048e9ab0834ac6d41 (patch)
tree3239e46294bfd6bbf897e1a2470a2fad20fef653 /src/backend/access/transam/xlogarchive.c
parentb8e20d6dabdafbe905b62910dc0236037c7881e1 (diff)
downloadpostgresql-e09ad07b21a244c3cbcdbe3048e9ab0834ac6d41.tar.gz
postgresql-e09ad07b21a244c3cbcdbe3048e9ab0834ac6d41.zip
Move routine building restore_command to src/common/
restore_command has only been used until now by the backend, but there is a pending patch for pg_rewind to make use of that in the frontend. Author: Alexey Kondratov Reviewed-by: Andrey Borodin, Andres Freund, Alvaro Herrera, Alexander Korotkov, Michael Paquier Discussion: https://postgr.es/m/a3acff50-5a0d-9a2c-b3b2-ee36168955c1@postgrespro.ru
Diffstat (limited to 'src/backend/access/transam/xlogarchive.c')
-rw-r--r--src/backend/access/transam/xlogarchive.c66
1 files changed, 10 insertions, 56 deletions
diff --git a/src/backend/access/transam/xlogarchive.c b/src/backend/access/transam/xlogarchive.c
index 188b73e7526..914ad340eae 100644
--- a/src/backend/access/transam/xlogarchive.c
+++ b/src/backend/access/transam/xlogarchive.c
@@ -21,6 +21,7 @@
#include "access/xlog.h"
#include "access/xlog_internal.h"
+#include "common/archive.h"
#include "miscadmin.h"
#include "postmaster/startup.h"
#include "replication/walsender.h"
@@ -53,11 +54,8 @@ RestoreArchivedFile(char *path, const char *xlogfname,
bool cleanupEnabled)
{
char xlogpath[MAXPGPATH];
- char xlogRestoreCmd[MAXPGPATH];
+ char *xlogRestoreCmd;
char lastRestartPointFname[MAXPGPATH];
- char *dp;
- char *endp;
- const char *sp;
int rc;
struct stat stat_buf;
XLogSegNo restartSegNo;
@@ -149,58 +147,13 @@ RestoreArchivedFile(char *path, const char *xlogfname,
else
XLogFileName(lastRestartPointFname, 0, 0L, wal_segment_size);
- /*
- * construct the command to be executed
- */
- dp = xlogRestoreCmd;
- endp = xlogRestoreCmd + MAXPGPATH - 1;
- *endp = '\0';
-
- for (sp = recoveryRestoreCommand; *sp; sp++)
- {
- if (*sp == '%')
- {
- switch (sp[1])
- {
- case 'p':
- /* %p: relative path of target file */
- sp++;
- StrNCpy(dp, xlogpath, endp - dp);
- make_native_path(dp);
- dp += strlen(dp);
- break;
- case 'f':
- /* %f: filename of desired file */
- sp++;
- StrNCpy(dp, xlogfname, endp - dp);
- dp += strlen(dp);
- break;
- case 'r':
- /* %r: filename of last restartpoint */
- sp++;
- StrNCpy(dp, lastRestartPointFname, endp - dp);
- dp += strlen(dp);
- break;
- case '%':
- /* convert %% to a single % */
- sp++;
- if (dp < endp)
- *dp++ = *sp;
- break;
- default:
- /* otherwise treat the % as not special */
- if (dp < endp)
- *dp++ = *sp;
- break;
- }
- }
- else
- {
- if (dp < endp)
- *dp++ = *sp;
- }
- }
- *dp = '\0';
+ /* Build the restore command to execute */
+ xlogRestoreCmd = BuildRestoreCommand(recoveryRestoreCommand,
+ xlogpath, xlogfname,
+ lastRestartPointFname);
+ if (xlogRestoreCmd == NULL)
+ elog(ERROR, "could not build restore command \"%s\"",
+ recoveryRestoreCommand);
ereport(DEBUG3,
(errmsg_internal("executing restore command \"%s\"",
@@ -217,6 +170,7 @@ RestoreArchivedFile(char *path, const char *xlogfname,
rc = system(xlogRestoreCmd);
PostRestoreCommand();
+ pfree(xlogRestoreCmd);
if (rc == 0)
{