mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-01-18 04:58:51 +02:00
Remove special protocol encoding for StorageType.
It seems like overkill to encode this when other enums (e.g. StorageInfoLevel) are passed as integers. Instead note that StorageType values should not be changed and remove the special encoding.
This commit is contained in:
parent
afe1568bb1
commit
9f1e7d88da
@ -26,14 +26,14 @@ typedef enum
|
||||
} StorageInfoLevel;
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Storage type
|
||||
Storage types. The values are used in the remote protocol so must not be changed.
|
||||
***********************************************************************************************************************************/
|
||||
typedef enum
|
||||
{
|
||||
storageTypeFile,
|
||||
storageTypePath,
|
||||
storageTypeLink,
|
||||
storageTypeSpecial,
|
||||
storageTypeFile = 0,
|
||||
storageTypePath = 1,
|
||||
storageTypeLink = 2,
|
||||
storageTypeSpecial = 3,
|
||||
} StorageType;
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
|
@ -90,49 +90,9 @@ storageRemoteFilterGroup(IoFilterGroup *filterGroup, const Variant *filterList)
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Write storage info into the protocol
|
||||
Write storage info into the protocol. This function is not called unless the info exists so no need to write exists or check for
|
||||
level == storageInfoLevelExists.
|
||||
***********************************************************************************************************************************/
|
||||
// Helper to write storage type into the protocol
|
||||
static void
|
||||
storageRemoteInfoWriteType(ProtocolServer *server, StorageType type)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(PROTOCOL_SERVER, server);
|
||||
FUNCTION_TEST_PARAM(ENUM, type);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case storageTypeFile:
|
||||
{
|
||||
protocolServerWriteLine(server, STRDEF("f"));
|
||||
break;
|
||||
}
|
||||
|
||||
case storageTypePath:
|
||||
{
|
||||
protocolServerWriteLine(server, STRDEF("p"));
|
||||
break;
|
||||
}
|
||||
|
||||
case storageTypeLink:
|
||||
{
|
||||
protocolServerWriteLine(server, STRDEF("l"));
|
||||
break;
|
||||
}
|
||||
|
||||
case storageTypeSpecial:
|
||||
{
|
||||
protocolServerWriteLine(server, STRDEF("s"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FUNCTION_TEST_RETURN_VOID();
|
||||
}
|
||||
|
||||
// Helper to write storage info into the protocol. This function is not called unless the info exists so no need to write exists
|
||||
// or check for level == storageInfoLevelExists.
|
||||
static void
|
||||
storageRemoteInfoWrite(ProtocolServer *server, const StorageInfo *info)
|
||||
{
|
||||
@ -141,7 +101,7 @@ storageRemoteInfoWrite(ProtocolServer *server, const StorageInfo *info)
|
||||
FUNCTION_TEST_PARAM(STORAGE_INFO, info);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
storageRemoteInfoWriteType(server, info->type);
|
||||
protocolServerWriteLine(server, jsonFromUInt(info->type));
|
||||
protocolServerWriteLine(server, jsonFromInt64(info->timeModified));
|
||||
|
||||
if (info->type == storageTypeFile)
|
||||
|
@ -30,32 +30,6 @@ struct StorageRemote
|
||||
};
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
// Helper to convert protocol storage type to an enum
|
||||
static StorageType
|
||||
storageRemoteInfoParseType(const char type)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(CHAR, type);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case 'f':
|
||||
FUNCTION_TEST_RETURN(storageTypeFile);
|
||||
|
||||
case 'p':
|
||||
FUNCTION_TEST_RETURN(storageTypePath);
|
||||
|
||||
case 'l':
|
||||
FUNCTION_TEST_RETURN(storageTypeLink);
|
||||
|
||||
case 's':
|
||||
FUNCTION_TEST_RETURN(storageTypeSpecial);
|
||||
}
|
||||
|
||||
THROW_FMT(AssertError, "unknown storage type '%c'", type);
|
||||
}
|
||||
|
||||
// Helper to parse storage info from the protocol output
|
||||
static void
|
||||
storageRemoteInfoParse(ProtocolClient *client, StorageInfo *info)
|
||||
@ -65,7 +39,7 @@ storageRemoteInfoParse(ProtocolClient *client, StorageInfo *info)
|
||||
FUNCTION_TEST_PARAM(STORAGE_INFO, info);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
info->type = storageRemoteInfoParseType(strZ(protocolClientReadLine(client))[0]);
|
||||
info->type = jsonToUInt(protocolClientReadLine(client));
|
||||
info->timeModified = (time_t)jsonToUInt64(protocolClientReadLine(client));
|
||||
|
||||
if (info->type == storageTypeFile)
|
||||
|
@ -88,12 +88,6 @@ testRun(void)
|
||||
Storage *storageRemote = NULL;
|
||||
TEST_ASSIGN(storageRemote, storageRepoGet(strNew(STORAGE_POSIX_TYPE), true), "get remote repo storage");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("storage types that are not tested elsewhere");
|
||||
|
||||
TEST_RESULT_UINT(storageRemoteInfoParseType('s'), storageTypeSpecial, "read special type");
|
||||
TEST_ERROR(storageRemoteInfoParseType('z'), AssertError, "unknown storage type 'z'");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("missing file/path");
|
||||
|
||||
@ -191,17 +185,6 @@ testRun(void)
|
||||
TEST_RESULT_UINT(info.groupId, getgid(), " check group id");
|
||||
TEST_RESULT_STR_Z(info.group, testGroup(), " check group");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("protocol storage types that are not tested elsewhere");
|
||||
|
||||
TEST_RESULT_VOID(storageRemoteInfoWriteType(server, storageTypePath), "write path type");
|
||||
TEST_RESULT_VOID(storageRemoteInfoWriteType(server, storageTypeSpecial), "write special type");
|
||||
|
||||
ioWriteFlush(serverWriteIo);
|
||||
TEST_RESULT_STR_Z(strNewBuf(serverWrite), ".p\n.s\n", "check result");
|
||||
|
||||
bufUsedSet(serverWrite, 0);
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("protocol output that is not tested elsewhere (basic)");
|
||||
|
||||
@ -209,7 +192,7 @@ testRun(void)
|
||||
TEST_RESULT_VOID(storageRemoteInfoWrite(server, &info), "write link info");
|
||||
|
||||
ioWriteFlush(serverWriteIo);
|
||||
TEST_RESULT_STR_Z(strNewBuf(serverWrite), ".l\n.0\n.0\n.null\n.0\n.null\n.0\n.\"../\"\n", "check result");
|
||||
TEST_RESULT_STR_Z(strNewBuf(serverWrite), ".2\n.0\n.0\n.null\n.0\n.null\n.0\n.\"../\"\n", "check result");
|
||||
|
||||
bufUsedSet(serverWrite, 0);
|
||||
|
||||
@ -244,7 +227,7 @@ testRun(void)
|
||||
strNewBuf(serverWrite),
|
||||
hrnReplaceKey(
|
||||
"{\"out\":true}\n"
|
||||
".f\n.1555160001\n.6\n"
|
||||
".0\n.1555160001\n.6\n"
|
||||
"{}\n"),
|
||||
"check result");
|
||||
|
||||
@ -263,7 +246,7 @@ testRun(void)
|
||||
strNewBuf(serverWrite),
|
||||
hrnReplaceKey(
|
||||
"{\"out\":true}\n"
|
||||
".f\n.1555160001\n.6\n.{[user-id]}\n.\"{[user]}\"\n.{[group-id]}\n.\"{[group]}\"\n.416\n"
|
||||
".0\n.1555160001\n.6\n.{[user-id]}\n.\"{[user]}\"\n.{[group-id]}\n.\"{[group]}\"\n.416\n"
|
||||
"{}\n"),
|
||||
"check result");
|
||||
|
||||
@ -322,8 +305,8 @@ testRun(void)
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewBuf(serverWrite),
|
||||
hrnReplaceKey(
|
||||
".\".\"\n.p\n.1555160000\n.{[user-id]}\n.\"{[user]}\"\n.{[group-id]}\n.\"{[group]}\"\n.488\n"
|
||||
".\"test\"\n.f\n.1555160001\n.6\n.{[user-id]}\n.\"{[user]}\"\n.{[group-id]}\n.\"{[group]}\"\n.416\n"
|
||||
".\".\"\n.1\n.1555160000\n.{[user-id]}\n.\"{[user]}\"\n.{[group-id]}\n.\"{[group]}\"\n.488\n"
|
||||
".\"test\"\n.0\n.1555160001\n.6\n.{[user-id]}\n.\"{[user]}\"\n.{[group-id]}\n.\"{[group]}\"\n.416\n"
|
||||
".\n"
|
||||
"{\"out\":true}\n"),
|
||||
"check result");
|
||||
|
Loading…
x
Reference in New Issue
Block a user