* BuildRestoreCommand * * Builds a restore command to retrieve a file from WAL archives, replacing * the supported aliases with values supplied by the caller as defined by * the GUC parameter restore_command: xlogpath for %p, xlogfname for %f and * lastRestartPointFname for %r. * * The result is a palloc'd string for the restore command built. The * caller is responsible for freeing it.
| 40 | * by the caller, then NULL is returned. |
| 41 | */ |
| 42 | char * |
| 43 | BuildRestoreCommand(const char *restoreCommand, |
| 44 | const char *xlogpath, |
| 45 | const char *xlogfname, |
| 46 | const char *lastRestartPointFname) |
| 47 | { |
| 48 | StringInfoData result; |
| 49 | const char *sp; |
| 50 | #ifndef FRONTEND |
| 51 | char contentid[12]; /* sign, 10 digits and '\0' */ |
| 52 | #endif |
| 53 | |
| 54 | /* |
| 55 | * Build the command to be executed. |
| 56 | */ |
| 57 | initStringInfo(&result); |
| 58 | |
| 59 | for (sp = restoreCommand; *sp; sp++) |
| 60 | { |
| 61 | if (*sp == '%') |
| 62 | { |
| 63 | switch (sp[1]) |
| 64 | { |
| 65 | case 'p': |
| 66 | { |
| 67 | char *nativePath; |
| 68 | |
| 69 | /* %p: relative path of target file */ |
| 70 | if (xlogpath == NULL) |
| 71 | { |
| 72 | pfree(result.data); |
| 73 | return NULL; |
| 74 | } |
| 75 | sp++; |
| 76 | |
| 77 | /* |
| 78 | * This needs to use a placeholder to not modify the |
| 79 | * input with the conversion done via |
| 80 | * make_native_path(). |
| 81 | */ |
| 82 | nativePath = pstrdup(xlogpath); |
| 83 | make_native_path(nativePath); |
| 84 | appendStringInfoString(&result, |
| 85 | nativePath); |
| 86 | pfree(nativePath); |
| 87 | break; |
| 88 | } |
| 89 | case 'f': |
| 90 | /* %f: filename of desired file */ |
| 91 | if (xlogfname == NULL) |
| 92 | { |
| 93 | pfree(result.data); |
| 94 | return NULL; |
| 95 | } |
| 96 | sp++; |
| 97 | appendStringInfoString(&result, xlogfname); |
| 98 | break; |
| 99 | case 'r': |
no test coverage detected