diff options
Diffstat (limited to 'src/common/archive.c')
-rw-r--r-- | src/common/archive.c | 85 |
1 files changed, 12 insertions, 73 deletions
diff --git a/src/common/archive.c b/src/common/archive.c index 1466f67ea69..de42e914f74 100644 --- a/src/common/archive.c +++ b/src/common/archive.c @@ -20,7 +20,7 @@ #endif #include "common/archive.h" -#include "lib/stringinfo.h" +#include "common/percentrepl.h" /* * BuildRestoreCommand @@ -41,81 +41,20 @@ BuildRestoreCommand(const char *restoreCommand, const char *xlogfname, const char *lastRestartPointFname) { - StringInfoData result; - const char *sp; + char *nativePath = NULL; + char *result; - /* - * Build the command to be executed. - */ - initStringInfo(&result); - - for (sp = restoreCommand; *sp; sp++) + if (xlogpath) { - if (*sp == '%') - { - switch (sp[1]) - { - case 'p': - { - char *nativePath; + nativePath = pstrdup(xlogpath); + make_native_path(nativePath); + } - /* %p: relative path of target file */ - if (xlogpath == NULL) - { - pfree(result.data); - return NULL; - } - sp++; + result = replace_percent_placeholders(restoreCommand, "restore_command", "frp", + xlogfname, lastRestartPointFname, nativePath); - /* - * This needs to use a placeholder to not modify the - * input with the conversion done via - * make_native_path(). - */ - nativePath = pstrdup(xlogpath); - make_native_path(nativePath); - appendStringInfoString(&result, - nativePath); - pfree(nativePath); - break; - } - case 'f': - /* %f: filename of desired file */ - if (xlogfname == NULL) - { - pfree(result.data); - return NULL; - } - sp++; - appendStringInfoString(&result, xlogfname); - break; - case 'r': - /* %r: filename of last restartpoint */ - if (lastRestartPointFname == NULL) - { - pfree(result.data); - return NULL; - } - sp++; - appendStringInfoString(&result, - lastRestartPointFname); - break; - case '%': - /* convert %% to a single % */ - sp++; - appendStringInfoChar(&result, *sp); - break; - default: - /* otherwise treat the % as not special */ - appendStringInfoChar(&result, *sp); - break; - } - } - else - { - appendStringInfoChar(&result, *sp); - } - } + if (nativePath) + pfree(nativePath); - return result.data; + return result; } |