If a keyring is empty, store a no data flag instead of failing.

Any fully empty keyring (no keys and no applications) would fail to add
the empty flat buffer and thus prevent the whole keystore database from
being stored. This could easily happen when you used separate keyrings
but the master keyring was left unused for example.

Adding a flag that tells that there is no data allows us to distinguish
between a case where the stored data is missing due to a problem versus
an actually empty buffer.
This commit is contained in:
Michael Lotz 2013-03-31 18:30:39 +02:00
parent fa21184f24
commit 32057ce922

View File

@ -42,6 +42,11 @@ Keyring::ReadFromMessage(const BMessage& message)
if (result != B_OK)
return result;
if (message.GetBool("noData", false)) {
fFlatBuffer.SetSize(0);
return B_OK;
}
ssize_t size;
const void* data;
result = message.FindData("data", B_RAW_TYPE, &data, &size);
@ -69,8 +74,12 @@ Keyring::WriteToMessage(BMessage& message)
if (result != B_OK)
return result;
result = message.AddData("data", B_RAW_TYPE, fFlatBuffer.Buffer(),
fFlatBuffer.BufferLength());
if (fFlatBuffer.BufferLength() == 0)
result = message.AddBool("noData", true);
else {
result = message.AddData("data", B_RAW_TYPE, fFlatBuffer.Buffer(),
fFlatBuffer.BufferLength());
}
if (result != B_OK)
return result;