From fb174687f7a730edcf301949785a6ac0dbfd70d0 Mon Sep 17 00:00:00 2001 From: Fujii Masao Date: Thu, 2 Jul 2015 10:35:38 +0900 Subject: Make use of xlog_internal.h's macros in WAL-related utilities. Commit 179cdd09 added macros to check if a filename is a WAL segment or other such file. However there were still some instances of the strlen + strspn combination to check for that in WAL-related utilities like pg_archivecleanup. Those checks can be replaced with the macros. This patch makes use of the macros in those utilities and which would make the code a bit easier to read. Back-patch to 9.5. Michael Paquier --- contrib/pg_standby/pg_standby.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'contrib/pg_standby') diff --git a/contrib/pg_standby/pg_standby.c b/contrib/pg_standby/pg_standby.c index 2f9f2b4d2e9..861caea3481 100644 --- a/contrib/pg_standby/pg_standby.c +++ b/contrib/pg_standby/pg_standby.c @@ -32,6 +32,8 @@ #include "pg_getopt.h" +#include "access/xlog_internal.h" + const char *progname; /* Options and defaults */ @@ -57,7 +59,7 @@ char *restartWALFileName; /* the file from which we can restart restore */ char *priorWALFileName; /* the file we need to get from archive */ char WALFilePath[MAXPGPATH]; /* the file path including archive */ char restoreCommand[MAXPGPATH]; /* run this to restore */ -char exclusiveCleanupFileName[MAXPGPATH]; /* the file we need to +char exclusiveCleanupFileName[MAXFNAMELEN]; /* the file we need to * get from archive */ /* @@ -113,11 +115,6 @@ struct stat stat_buf; * folded in to later versions of this program. */ -#define XLOG_DATA_FNAME_LEN 24 -/* Reworked from access/xlog_internal.h */ -#define XLogFileName(fname, tli, log, seg) \ - snprintf(fname, XLOG_DATA_FNAME_LEN + 1, "%08X%08X%08X", tli, log, seg) - /* * Initialize allows customized commands into the warm standby program. * @@ -182,10 +179,7 @@ CustomizableNextWALFileReady() * If it's a backup file, return immediately. If it's a regular file * return only if it's the right size already. */ - if (strlen(nextWALFileName) > 24 && - strspn(nextWALFileName, "0123456789ABCDEF") == 24 && - strcmp(nextWALFileName + strlen(nextWALFileName) - strlen(".backup"), - ".backup") == 0) + if (IsBackupHistoryFileName(nextWALFileName)) { nextWALFileType = XLOG_BACKUP_LABEL; return true; @@ -261,8 +255,7 @@ CustomizableCleanupPriorWALFiles(void) * are not removed in the order they were originally written, * in case this worries you. */ - if (strlen(xlde->d_name) == XLOG_DATA_FNAME_LEN && - strspn(xlde->d_name, "0123456789ABCDEF") == XLOG_DATA_FNAME_LEN && + if (IsXLogFileName(xlde->d_name) && strcmp(xlde->d_name + 8, exclusiveCleanupFileName + 8) < 0) { #ifdef WIN32 @@ -366,7 +359,7 @@ SetWALFileNameForCleanup(void) } } - XLogFileName(exclusiveCleanupFileName, tli, log, seg); + XLogFileNameById(exclusiveCleanupFileName, tli, log, seg); return cleanup; } @@ -740,10 +733,7 @@ main(int argc, char **argv) * Check for initial history file: always the first file to be requested * It's OK if the file isn't there - all other files need to wait */ - if (strlen(nextWALFileName) > 8 && - strspn(nextWALFileName, "0123456789ABCDEF") == 8 && - strcmp(nextWALFileName + strlen(nextWALFileName) - strlen(".history"), - ".history") == 0) + if (IsTLHistoryFileName(nextWALFileName)) { nextWALFileType = XLOG_HISTORY; if (RestoreWALFileForRecovery()) -- cgit v1.2.3