From 08d9e269c6f03e7797584e90c53eb0743b787f60 Mon Sep 17 00:00:00 2001 From: David Steele Date: Tue, 5 Apr 2022 09:14:56 -0400 Subject: [PATCH] Refactor target type checking for clarity in restore module. This avoids using targetTime != 0 as an indicator that a time target was selected. --- src/command/restore/restore.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/command/restore/restore.c b/src/command/restore/restore.c index 333beb461..df8d53b55 100644 --- a/src/command/restore/restore.c +++ b/src/command/restore/restore.c @@ -240,12 +240,13 @@ restoreBackupSet(void) // If the set option was not provided by the user but a time to recover was set, then we will need to search for a backup // set that satisfies the time condition, else we will use the backup provided const String *backupSetRequested = NULL; - time_t timeTargetEpoch = 0; + const StringId targetType = cfgOptionStrId(cfgOptType); + time_t targetTime = 0; if (cfgOptionSource(cfgOptSet) == cfgSourceDefault) { - if (cfgOptionStrId(cfgOptType) == CFGOPTVAL_TYPE_TIME) - timeTargetEpoch = getEpoch(cfgOptionStr(cfgOptTarget)); + if (targetType == CFGOPTVAL_TYPE_TIME) + targetTime = getEpoch(cfgOptionStr(cfgOptTarget)); } else backupSetRequested = cfgOptionStr(cfgOptSet); @@ -290,7 +291,7 @@ restoreBackupSet(void) InfoBackupData latestBackup = infoBackupData(infoBackup, infoBackupDataTotal(infoBackup) - 1); // If the recovery type is time, attempt to determine the backup set - if (timeTargetEpoch != 0) + if (targetType == CFGOPTVAL_TYPE_TIME) { bool found = false; @@ -301,7 +302,7 @@ restoreBackupSet(void) InfoBackupData backupData = infoBackupData(infoBackup, keyIdx); // If the end of the backup is before the target time, then select this backup - if (backupData.backupTimestampStop < timeTargetEpoch) + if (backupData.backupTimestampStop < targetTime) { found = true; @@ -345,7 +346,7 @@ restoreBackupSet(void) { if (backupSetRequested != NULL) THROW_FMT(BackupSetInvalidError, "backup set %s is not valid", strZ(backupSetRequested)); - else if (timeTargetEpoch != 0) + else if (targetType == CFGOPTVAL_TYPE_TIME) { THROW_FMT( BackupSetInvalidError, "unable to find backup set with stop time less than '%s'",