Move function parse_repmgr_version() to a more appropriate location

This commit is contained in:
Ian Barwick
2019-09-17 15:59:56 +09:00
parent 8e6d111f32
commit a502b2cf96
4 changed files with 42 additions and 41 deletions

View File

@@ -373,42 +373,3 @@ enable_wal_receiver(PGconn *conn, bool wait_startup)
}
/**
* Parse the string returned by "repmgr --version", e.g. "repmgr 4.1.2",
* and return it as a version integer (e.g. 40102).
*
* This is required for backwards compatibility as versions prior to
* 4.3 do not have the --version-number option.
*/
int
parse_repmgr_version(const char *version_string)
{
int series, major, minor;
int version_integer = UNKNOWN_REPMGR_VERSION_NUM;
PQExpBufferData sscanf_string;
initPQExpBuffer(&sscanf_string);
appendPQExpBuffer(&sscanf_string, "%s ",
progname());
appendPQExpBufferStr(&sscanf_string, "%i.%i.%i");
if (sscanf(version_string, sscanf_string.data, &series, &major, &minor) == 3)
{
version_integer = (series * 10000) + (major * 100) + minor;
}
else
{
resetPQExpBuffer(&sscanf_string);
appendPQExpBuffer(&sscanf_string, "%s ",
progname());
appendPQExpBufferStr(&sscanf_string, "%i.%i");
if (sscanf(version_string, "repmgr %i.%i", &series, &major) == 2)
{
version_integer = (series * 10000) + (major * 100);
}
}
return version_integer;
}