1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-12 10:04:14 +02:00

Add repoIsLocalVerify() to verify repository locality.

Some commands can only be run on a host where the repository is local.  This function centralizes the check and error.

Contributed by Cynthia Shang.
This commit is contained in:
Cynthia Shang 2019-08-21 11:41:36 -04:00 committed by David Steele
parent 6a09d9294d
commit 27e8235812
3 changed files with 17 additions and 0 deletions

View File

@ -68,6 +68,20 @@ repoIsLocal(void)
FUNCTION_TEST_RETURN(!cfgOptionTest(cfgOptRepoHost));
}
/***********************************************************************************************************************************
Error if the repository is not local
***********************************************************************************************************************************/
void
repoIsLocalVerify(void)
{
FUNCTION_TEST_VOID();
if (!repoIsLocal())
THROW_FMT(HostInvalidError, "%s command must be run on the repository host", cfgCommandName(cfgCommand()));
FUNCTION_TEST_RETURN_VOID();
}
/***********************************************************************************************************************************
Is pg local?
***********************************************************************************************************************************/

View File

@ -35,6 +35,7 @@ Getters
***********************************************************************************************************************************/
bool pgIsLocal(unsigned int hostId);
bool repoIsLocal(void);
void repoIsLocalVerify(void);
/***********************************************************************************************************************************
Destructor

View File

@ -75,6 +75,7 @@ testRun(void)
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
TEST_RESULT_BOOL(repoIsLocal(), true, "repo is local");
TEST_RESULT_VOID(repoIsLocalVerify(), " local verified");
// -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew();
@ -85,6 +86,7 @@ testRun(void)
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
TEST_RESULT_BOOL(repoIsLocal(), false, "repo is remote");
TEST_ERROR_FMT(repoIsLocalVerify(), HostInvalidError, "archive-get command must be run on the repository host");
// -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew();